Global.asax中的base.BeginRequest没有受到打击? [英] base.BeginRequest in Global.asax not getting hit?
问题描述
我正在尝试理解URL重写.在我的Global.asax文件中,有以下一行:
Im trying to understand URL re-writing. In my Global.asax file I have the line:
base.BeginRequest += new EventHandler(Global_BeginRequest);
在Session_Start方法中.它命中并创建了它,但是它从未命中过事件处理程序?有任何想法吗?
in the Session_Start method. It hits the line and creates it, but it never hits the event handler? Any ideas why?
推荐答案
据我所知,您应该通过以下方式在IHttpModule的init方法中实现事件处理程序:
Hi,
As far as I know, you should implement the event-handler in a IHttpModule''s init method this way:
public void Init(HttpApplication context)
{
context.BeginRequest += context_BeginRequest;
}
并添加您在web.config httpModule-/modules-Section中创建的HttpModule类:
and add the HttpModule class you created in the web.config httpModule- / modules-Section:
<configuration>
<system.web>
<httpmodules>
<clear />
<add name="RedirectHandler" type="RedirectorModule.RedirectHandler" />
<add name="RewriteHandler" type="RedirectorModule.RewriteHandler" />
</httpmodules>
</system.web>
<system.webserver>
<modules runallmanagedmodulesforallrequests="true">
<remove name="RedirectHandler" />
<add name="RedirectHandler" type="RedirectorModule.RedirectHandler" />
<remove name="RewriteHandler" />
<add name="RewriteHandler" type="RedirectorModule.RewriteHandler" />
</modules>
</system.webserver>
</configuration>
有关更多信息,我做了一个有关基本URL重写器的博客条目:
http://blog. dotnetcorner.ch/post/2011/03/30/How-to-Create-an-easy-and-flexible-URL-Rewriter.aspx [
For more informations, I made a blog entry about a basic URL Rewriter:
http://blog.dotnetcorner.ch/post/2011/03/30/How-to-Create-an-easy-and-flexible-URL-Rewriter.aspx[^]
Hope this helps.
Best regards and happy coding,
Stops
-- UPDATE: added Web.config modifications.
这篇关于Global.asax中的base.BeginRequest没有受到打击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!