C# 我应该在IHTTP模块中使用什么事件来禁用网站?

C# 我应该在IHTTP模块中使用什么事件来禁用网站?,c#,asp.net,httpmodule,C#,Asp.net,Httpmodule,出于许可的原因,我想通过编程禁用一个网站,我想在httpmodule中这样做 我试图改变上下文: public void Init(HttpApplication context) { context.Response.Redirect("http://vls.pete.videolibraryserver.com"); } 但我得到了一个错误: Response is not available in this context. 任何人都知道如何有效地禁用网站,最好将其发送到自定义

出于许可的原因,我想通过编程禁用一个网站,我想在httpmodule中这样做

我试图改变上下文:

public void Init(HttpApplication context)
{
    context.Response.Redirect("http://vls.pete.videolibraryserver.com");
}
但我得到了一个错误:

Response is not available in this context.

任何人都知道如何有效地禁用网站,最好将其发送到自定义页面。

您可以使用
BeginRequest
事件进行重定向,如下所示:

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

使用
Server.Transfer
,因为如果自定义页面位于同一台机器上,这将节省往返时间;(这是我自己回答的问题-不想自我推销)

也许关闭网站的更好方法是通过编程将App_Offline.htm文件写入网站的根目录。引自:

“app_offline.htm的工作方式是 将此文件放在 当ASP.NET看到它时,它 将关闭应用程序的应用程序域 应用程序(而不是重新启动) 请求),并将 app_offline.htm文件的内容 为了响应所有新的动态 申请。什么时候 您已经完成了站点更新,只需 删除该文件,它将返回 在线。”

public void Init(HttpApplication上下文)
{
context.Response.Write(“对于许可证,请访问此”);
context.Response.End();
}
您可以使用此代码

public void Init(HttpApplication context)
{

    context.Response.Write("for licence visit this <a href=\"http://vls.pete.videolibraryserver.com\">link</a>");
    context.Response.End();

}