如何解决如何在 ASP.NET web 应用程序中禁用单个 aspx 页面?
想要在 ASP.NET Web 应用程序中禁用单个 aspx 页面并在应用程序仍在运行时显示消息“此页面正在维护中”。这可能吗?
解决方法
在 Application_BeginRequest
的 global.asax
上执行此操作的一种方法。检查是否调用了特定文件并显示其他一些静态页面并在那里结束进程。方法如下:
protected void Application_BeginRequest(Object sender,EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string cTheFileName = System.IO.Path.GetFileName(HttpContext.Current.Request.Path);
// if its the file you want to be offline
if (cTheFileName == 'filename.aspx')
{
// the file we look now is the app_offline_alt.htm
string cOffLineFile = HttpRuntime.AppDomainAppPath + "app_offline_alt.htm";
// if exist on root - if not we skip the offline mode.
// this way you can put it offline with just the existing of this file.
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;
}
}
}
app_offline_alt.htm
包含简单的维护中消息或您喜欢的任何内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。