4

We have a ASP.NET website in .NET which is running successfully in production. we have frequently maintain our server on a particular downtime. Hence, We need a feature to redirect all request to Site Under maintenance web page at downtime. I've accomplished this task with Custom Handler but my customer isn't happy with that solution. Please suggest some alternate solution.

My Custom Handler code as follows

Added Under web.config

    <system.webServer>
        <modules>
          <add name="CustomModule" type="CustomModule"/>
       </modules>
  </system.webserver>

Added Under Http Handler

public class CustomModule : IHttpModule
    {
        // In the Init function, register for HttpApplication 
        // events by adding your handlers.
        public void Init(HttpApplication application)
        {

            application.EndRequest +=
                (new EventHandler(this.Application_EndRequest));
        }
}

Redirect code goes here

private void Application_EndRequest(Object source, EventArgs e)
        {

            if (fileExtension.Equals(".aspx") == true && filePath.Contains("Contact.aspx") == false)
            {
                context.Response.Redirect("Contact.aspx");
            }
        }
4

3 回答 3

9

只需使用app_offline.htm ,这里这里都有解释。

如果您想让网站在特定时间段内(或其他一些外部事件等)保持关闭,那么您可以在服务器上运行(预定的)脚本以app_offline.htm在需要时创建或删除文件。

于 2013-08-05T17:55:06.497 回答
5

App_Offline.html会这样做。

在此处阅读有关App_Offline.html的信息。

于 2013-08-05T17:55:38.167 回答
0

如果无法将代码部署到生产服务器,那么使用计划任务批处理文件(或自定义程序)按计划部署和删除App_Offline.html文件怎么样?

于 2013-08-06T18:02:30.270 回答