Response.Redirect in HttpModule

最后都变了- 提交于 2019-12-02 02:34:53

问题


Can I do a redirect to a custom page in an HttpModule?

I have an HttpModule A which executes some javascript code when any aspx page is loaded. I would like to have a server side code check to see if the clients browsers supports cookies. Can I place that code in the HttpModule A? If so, in which event? Or do I need to have a new HttpHandler for both purposes?

Also, is it possible to check for cookies in an HttpModule(without a response.redirect)? All solutions I have seen need 2 pages, 1 for setting the cookie and the other for checking if the cookie has actually been created. I am hoping there should be a way to check for cookies at one place.

Thanks in advance


回答1:


Check this out.. http://www.15seconds.com/issue/030522.htm

The key being... Context.RewritePath()

MDSN http://msdn.microsoft.com/en-us/library/system.web.httpcontext.rewritepath.aspx




回答2:


You can use the same HttpHandler for both. The cookie check just needs to go in an event before the page handler gets called, such as the "BeginRequest" event. Then you can use the Response.Redirect or Context.RewritePath.



来源:https://stackoverflow.com/questions/1348380/response-redirect-in-httpmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!