问题
When does routing take place in the ASP.NET MVC pipeline?
ASP.NET Application Life Cycle Overview for IIS 7.0
Is it in step number 2 (Perform Url Mapping)?
I intend to have a few routes that have an id
"activate/{id}"
"forgotpassword/{id}"
I would like to be able to access the id early on in the pipline in step 4 - AuthenticateRequest. So that I can pass an authentication token through the id part of the url to my custom authentication module.
So can I access the id property in my custom authentication module or do I have to manually extract it from the request url?
Thanks for your help,
Duncan
回答1:
It appears that the UrlRouting takes place at step number 9 - PostResolveRequestCache.
So it does in fact take place after AuthenticateRequest which is step number 4.
This is the document for UrlRoutingModule
I looked up it's Init() method in reflector and that is where it subscribes to the PostResolveRequestCache Event.
So I guess now I have to try and write some code that elegantly extracts the token from the url manually..
回答2:
I know its not the answer you want - but from a security standpoint tokens in the uri are a bad idea. They can be read by javascript and then sent off to any other site in the world.
To answer your question though, routing is an httpmodule, so it takes place very early but happens after your authentication. see: http://msdn.microsoft.com/en-us/magazine/dd347546.aspx#id0070044
来源:https://stackoverflow.com/questions/6100935/when-does-routing-take-place-in-the-pipeline