管道中何时进行路由?
ASP.NET MVC 管道中何时进行路由?
是否按步骤进行第 2 号(执行 URL 映射)?
我打算有一些具有 id
“activate/{id}”
“forgotpassword/{id}”
的路由,我希望能够在步骤 4 - AuthenticateRequest 的管道中尽早访问该 id。这样我就可以通过 url 的 id 部分将身份验证令牌传递到我的自定义身份验证模块。
那么我可以在自定义身份验证模块中访问 id 属性,还是必须手动从请求 URL 中提取它?
感谢您的帮助,
邓肯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来 UrlRouting 发生在第 9 步 - PostResolveRequestCache。
因此,它实际上发生在第 4 步 AuthenticateRequest 之后。
这是 UrlRoutingModule 的文档
我在反射器中查找了它的 Init() 方法,这就是它订阅 PostResolveRequestCache 事件的地方。
所以我想现在我必须尝试编写一些代码来优雅地手动从 url 中提取令牌。
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..
我知道这不是您想要的答案 - 但从安全角度来看,URI 中的令牌是一个坏主意。它们可以通过 JavaScript 读取,然后发送到世界上任何其他站点。
不过,为了回答你的问题,路由是一个 httpmodule,所以它很早就发生,但发生在你的身份验证之后。请参阅:http://msdn.microsoft.com/en-us/magazine /dd347546.aspx#id0070044
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