IIS 上用于外部访问者的维护页面的网站关闭
Website down for maintenance page on IIS for external visitors
我想关闭一个网站以供 "external" 访问者维护,同时我在 IIS 托管的网站上进行一些主要部署。我读过有关在网络根目录中创建 "App_Offline.htm" 页面的内容。我是否仍然可以在 localhost 下浏览网站(我将登录到服务器),而访问者通过域名浏览将看到 "down for maintenance" 页面?在将更改提供给访问者之前,我想做一些测试。
默认情况下,当您打开 app_offline.htm
时,asp.net 会停止来自 运行 的网页。
但是您可以通过 global.asax 上的一些编程来实现:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
// if its not local - let see if we go offline
if (!app.Request.IsLocal)
{
// the file we look now is the app_offline_alt.htm
string cOffLineFile = HttpRuntime.AppDomainAppPath + "app_offline_alt.htm";
// if exist on root
if (System.IO.File.Exists(cOffLineFile))
{
using (var fp = System.IO.File.OpenText(cOffLineFile))
{
// read it and send it to the browser
app.Response.Write(fp.ReadToEnd());
fp.Close();
}
// and stop the rest of processing
app.Response.End();
return;
}
}
}
我通过以下方式解决了这个问题:
- 我在 web.config 文件中添加了一个名为 "MaintanenceMode" 的密钥
<appSettings>
<add key="MaintenanceMode" value="true" />
</appSettings>
- 我在家庭控制器中添加了一个操作结果和视图
public class HomeController : BaseController
{
public ActionResult Offline()
{
return View("Offline");
}
}
- 我更改了 Global.asax.cs MaintenanceMode 密钥的文件检查,并将所有外部请求(图像、css 和 js 文件请求除外)重定向到离线页面
protected void Application_BeginRequest()
{
if (WebConfigurationManager.AppSettings["MaintenanceMode"] == "true")
{
if (!Request.IsLocal && !Request.Path.Contains("bundles") && !Request.Path.Contains("Content"))
{
HttpContext.Current.RewritePath("/home/offline");
}
}
}
我想关闭一个网站以供 "external" 访问者维护,同时我在 IIS 托管的网站上进行一些主要部署。我读过有关在网络根目录中创建 "App_Offline.htm" 页面的内容。我是否仍然可以在 localhost 下浏览网站(我将登录到服务器),而访问者通过域名浏览将看到 "down for maintenance" 页面?在将更改提供给访问者之前,我想做一些测试。
默认情况下,当您打开 app_offline.htm
时,asp.net 会停止来自 运行 的网页。
但是您可以通过 global.asax 上的一些编程来实现:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
// if its not local - let see if we go offline
if (!app.Request.IsLocal)
{
// the file we look now is the app_offline_alt.htm
string cOffLineFile = HttpRuntime.AppDomainAppPath + "app_offline_alt.htm";
// if exist on root
if (System.IO.File.Exists(cOffLineFile))
{
using (var fp = System.IO.File.OpenText(cOffLineFile))
{
// read it and send it to the browser
app.Response.Write(fp.ReadToEnd());
fp.Close();
}
// and stop the rest of processing
app.Response.End();
return;
}
}
}
我通过以下方式解决了这个问题:
- 我在 web.config 文件中添加了一个名为 "MaintanenceMode" 的密钥
<appSettings>
<add key="MaintenanceMode" value="true" />
</appSettings>
- 我在家庭控制器中添加了一个操作结果和视图
public class HomeController : BaseController
{
public ActionResult Offline()
{
return View("Offline");
}
}
- 我更改了 Global.asax.cs MaintenanceMode 密钥的文件检查,并将所有外部请求(图像、css 和 js 文件请求除外)重定向到离线页面
protected void Application_BeginRequest()
{
if (WebConfigurationManager.AppSettings["MaintenanceMode"] == "true")
{
if (!Request.IsLocal && !Request.Path.Contains("bundles") && !Request.Path.Contains("Content"))
{
HttpContext.Current.RewritePath("/home/offline");
}
}
}