Search code examples
c#asp.nethttpmodule

What event should I use in the IHttpModule to disable website?


I want to disable a website programatically for licensing reasons, and I want to do it in a httpmodule.

Ive tried to redirect the context :

public void Init(HttpApplication context)
{
    context.Response.Redirect("http://vls.pete.videolibraryserver.com");
}

But I get the error:

Response is not available in this context.

Anybody know how I can effectively disable the website and preferably send them to a custom page.


Solution

  • you can use BeginRequest event for redirection, like following:

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }
    
    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        application.Context.Response.Redirect("http://vls.pete.videolibraryserver.com");
    }