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 pr开发者_高级运维eferably send them to a custom page.
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");
}
Use Server.Transfer
as this will save a round trip provided the custom page is on the same machine; HTTPModule BeginRequest should us Response.Redirect or Server.Transfer (this is my own question I answered - not trying to be self promoting)
Perhaps a better way to close the site would be to programmatically write out an App_Offline.htm file to the root of the website. To quote from Scott Guthrie's blog:
"The way app_offline.htm works is that you place this file in the root of the application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online."
public void Init(HttpApplication context)
{
context.Response.Write("for licence visit this <a href=\"http://vls.pete.videolibraryserver.com\">link</a>");
context.Response.End();
}
you can use this code
精彩评论