I have created a custom AuthorizeAttribute which verifies some OAuth credentials that are sent inside the HTTP header. I am using some of these credentials to identify who is making the request. Once I parse this information in the AuthorizeAttribute is there any way to pass it over so that the data can be assigned to an instance variable of the Controller? Then anywhere in my Controller I will have the ID of the requesting party.
Original answer
You should be able to do this in your filter
filterContext.HttpContext.Items["test"] = "foo";
And then this in your action
_yourVariable = HttpContext.Items["test"];
You'd probably want to use a more unique key than "test"
, but that's the idea.
EDIT There are two reasons we do this in the action rather than the constructor:
Alternative solution
OAuthController : Controller
OnAuthorization
OAuthController.OnAuthorization
protected
field (i.e., protected object myAuthData
) in OAuthController
OAuthController
instead of Controller
myAuthData
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With