5

I have created an HttpModule so that Whenever I type "localhost/blabla.html" in the browser, it will redirect me to www.google.com (this is just an example, it's really to redirect requests coming from mobile phones)

My Questions are :

1) How do I tell IIS(7.0) to redirect each request to the "HttpModule" so that it is independent of the website. I can change the web.config but that's it.

2) Do I need to add the .dll to the GAC? If so, How can I do that?

3) The HttpModule code uses 'log4net' . do I need to add 'log4net' to the GAC as well?

Thanks

P.S. the site is using .net 2.0.

0

1 Answer 1

15

You can use request object in BeginRequest event

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");
          }
    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

I already have the code for the redirect module ready, I need to install it in IIS so that requests go through the HttpModule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.