Is it possible to access Controller/Action attributes from a Message Handler?
Asked Answered
S

1

6

Is there a practical way to access the attributes decorating a controller or action from a Message Handler/ DelegatingHandler?

From the diagram on Pedro Felix's blog entry, it looks like Message Handler's are too early in the pipeline and the info won't be available until the Controller Dispatcher Message Handler runs. Correct?

About my use case:
I'm working with the Thinktecture identity model, and it would be useful to be able to look for the AllowAnonymous attribute in the AuthenticationHandler.

Sarracenia answered 3/7, 2012 at 11:39 Comment(0)
I
2

By nature, this seems to be the wrong place to implement it. As you have noted, Message Handlers work across all requests and responses. If you depend on an attribute, this would naturally be a filter. So I suggest you follow that route.

In fact in the handler you cannot assume there is going to an ApiController or an action. Handlers can be equally used on clients.

Indole answered 3/7, 2012 at 15:5 Comment(3)
Thanks for the answer +1. I agree with your architectural observations whole heartedly; but sometimes you play the hand you're dealt. IdentityModel's AuthenticationHandler is implemented as a Message Handler. An invalid token stops processing and returns an HTTP 401. This is perfect for every situation...**except** for when you want an exemption for the method that issues valid tokens (assuming one is self issuing, instead of using a 3rd party service).Sarracenia
Best is to talk to Dominick - he is very open to suggestions when it fits the product. I have not yet looked at it in depth but need to pick up soon.Indole
Agreed - we've been going back and forth, and I'm crafting another email to him on the topic. I was looking for an alternative, to make integrating the changes less disruptive. BTW ...he's started showing up on SO a bit - stackoverflow.com/users/672453/leastprivilegeSarracenia

© 2022 - 2024 — McMap. All rights reserved.