Redirect URL using HttpModule Asp.net

I created an HttpModule, so whenever I type “localhost / blabla.html” in a browser, it redirects me to www.google.com (this is just an example, it really redirects requests coming from mobile phones)

My questions:

1) How to tell IIS (7.0) to forward each request to the "HttpModule" so that it does not depend on the website. I can change the web.config file, but what is it.

2) Do I need to add a DLL to the GAC? If so, how can I do this?

3) The HttpModule code uses "log4net". Do I need to add 'log4net' to the GAC?

thank

PS site uses .net 2.0.

+5
source share
1 answer

BeginRequest

public class MyHttpModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
          context.BeginRequest += new EventHandler(this.context_BeginRequest);
    }

    private void context_BeginRequest(object sender, EventArgs e)
    {
          HttpApplication application = (HttpApplication)sender;
          HttpContext context = application.Context;

          //check here context.Request for using request object 
          if(context.Request.FilePath.Contains("blahblah.html"))
          {
               context.Response.Redirect("http://www.google.com");
          }
    }

}
+11

All Articles