Let's suppose I want to use routing like this:
{sessionid}/{controller}/{action}/{id}
Adding a route is easy enough, but now I am unclear on how to get AuthorizeAttribute
to use the user associated with my session token. I looked at its source in ILSpy, and it seem to be relying on HttpContext
to get IPrincipal
, and that's where trail goes cold.
Where does it get this instance of IPrincipal
?
Worst case I imagine I could write a custom FilterAttribute
and a custom user class implementing IPrincipal
. Hook it up globally to get sessionid
from the route data, look up my user from DB and then just give my custom IPrincipal
instance to HttpContext.User
.
This seems a bit low level and also bypassing the whole MembershipProvider
business.
Am I on the right track or maybe there is an easier way to go about this?