1

I'm trying to get a custom attribute from a HttpContext but I don't know how to pick this specific attribute that I created. I already did a method like that, but was picking up the attribute from an IInvocation, but I don't know if I can do the same with the HttpContext.

The code that I'm trying to pick the Attribute https://i.stack.imgur.com/EZWTQ.png

The code that I did with IInvocation: https://i.stack.imgur.com/a0fKH.png

Renato
  • 13
  • 2
  • [Please do not upload images of code/errors when asking a question.](https://meta.stackoverflow.com/q/285551/8967612) – 41686d6564 stands w. Palestine Oct 14 '21 at 18:38
  • There's no attributes on an HttpContext. In aspnet, once it resolves via routing to an endpoint, it's the endpoint that has Metadata/attributes. If you have Middleware that's run before everything else you can't just grab an attribute based on the path. In the reverse (after the pipeline has run) you can pull some items out of the HttpContext.Features which will be set by the pipeline. This may include the actioncontext/descriptor (but it may not, I dunno). What you really need is the IActionContextAccessor.. But the metadata will only be there on the way back up the Middleware pipeline – pinkfloydx33 Oct 14 '21 at 23:04
  • Though this might help. https://stackoverflow.com/a/13045048/491907 – pinkfloydx33 Oct 14 '21 at 23:06

0 Answers0