Click here to Skip to main content
16,011,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to understand URL re-writing. In my Global.asax file I have the line:
base.BeginRequest += new EventHandler(Global_BeginRequest);

in the Session_Start method. It hits the line and creates it, but it never hits the event handler? Any ideas why?
Posted

1 solution

Hi,

As far as I know, you should implement the event-handler in a IHttpModule's init method this way:

C#
public void Init(HttpApplication context)
{
    context.BeginRequest += context_BeginRequest;
}


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>


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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900