【问题标题】:What event should I use in the IHttpModule to disable website?我应该在 IHttpModule 中使用什么事件来禁用网站?
【发布时间】:2010-12-03 09:33:06
【问题描述】:

出于许可原因,我想以编程方式禁用网站,并且我想在 httpmodule 中执行此操作。

我试图重定向上下文:

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

但我得到了错误:

Response is not available in this context.

任何人都知道我可以如何有效地禁用该网站并最好将它们发送到自定义页面。

【问题讨论】:

    标签: c# asp.net httpmodule


    【解决方案1】:

    您可以使用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");
    }
    

    【讨论】:

      【解决方案2】:

      使用Server.Transfer,因为如果自定义页面在同一台机器上,这将节省往返时间; HTTPModule BeginRequest should us Response.Redirect or Server.Transfer(这是我自己回答的问题——不是想自我推销)

      【讨论】:

        【解决方案3】:

        也许关闭网站的更好方法是以编程方式将 App_Offline.htm 文件写入网站的根目录。引用Scott Guthrie's blog:

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

        【讨论】:

          【解决方案4】:
          public void Init(HttpApplication context)
          {
          
              context.Response.Write("for licence visit this <a href=\"http://vls.pete.videolibraryserver.com\">link</a>");
              context.Response.End();
          
          }
          

          您可以使用此代码

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-01-13
            • 2017-11-18
            • 1970-01-01
            • 1970-01-01
            • 2010-12-17
            相关资源
            最近更新 更多