无法使用 RewritePath 在第一次请求时从 Application-BeginRequest 重定向
Can Not Redirect from Application-BeginRequest at First Request using RewritePath
我想在定义的维护中重定向到维护屏幕 window(在开始日期时间和结束日期时间之间)
在我的 Global.asax.cs 文件中:
protected void Application_BeginRequest(object sender, EventArgs e)
{
var maintStart = Convert.ToDateTime(CommonUtilities.GetAppConfigCredential("MaintenanceStartDateTime"));
var maintEnd = Convert.ToDateTime(CommonUtilities.GetAppConfigCredential("MaintenanceEndDateTime"));
DateTime nw = DateTime.Now;
if (maintStart < nw && nw < maintEnd)
{
HttpContext.Current.RewritePath("MaintenancePage");
}
}
如果我在维护 window 之外启动我的应用程序,然后等到 window 启动日期时间(或简单地更改配置),我将在下一个请求时被重定向到维护屏幕.但是,如果我在维护 window 期间尝试启动我的应用程序,我会收到以下错误:
Server Error in '/' Application.
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
不确定如何调试,或者我的下一步应该是什么。
编辑:
如果我在维护 window 中启动我的应用程序,我需要:
HttpContext.Current.RewritePath("Home/MaintenancePage");
使其正常工作。
如果我在维护 window 之外启动我的应用程序,然后等到维护 window 开始时间,我需要:
HttpContext.Current.RewritePath("MaintenancePage");
使其正常工作。
编辑2:
忘记说了,我有这个:
public ActionResult MaintenancePage()
{
return View();
}
在我的 HomeController 中。
而且我忘了提到维护页面在 Views/Home 文件夹中。
在我的 Global.asax.cs 文件中,在 Application_BeginRequest 中,这是正确的语句,具有正确的路径:
HttpContext.Current.RewritePath("/Home/MaintenancePage");
我想在定义的维护中重定向到维护屏幕 window(在开始日期时间和结束日期时间之间)
在我的 Global.asax.cs 文件中:
protected void Application_BeginRequest(object sender, EventArgs e)
{
var maintStart = Convert.ToDateTime(CommonUtilities.GetAppConfigCredential("MaintenanceStartDateTime"));
var maintEnd = Convert.ToDateTime(CommonUtilities.GetAppConfigCredential("MaintenanceEndDateTime"));
DateTime nw = DateTime.Now;
if (maintStart < nw && nw < maintEnd)
{
HttpContext.Current.RewritePath("MaintenancePage");
}
}
如果我在维护 window 之外启动我的应用程序,然后等到 window 启动日期时间(或简单地更改配置),我将在下一个请求时被重定向到维护屏幕.但是,如果我在维护 window 期间尝试启动我的应用程序,我会收到以下错误:
Server Error in '/' Application.
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
不确定如何调试,或者我的下一步应该是什么。
编辑:
如果我在维护 window 中启动我的应用程序,我需要:
HttpContext.Current.RewritePath("Home/MaintenancePage");
使其正常工作。
如果我在维护 window 之外启动我的应用程序,然后等到维护 window 开始时间,我需要:
HttpContext.Current.RewritePath("MaintenancePage");
使其正常工作。
编辑2:
忘记说了,我有这个:
public ActionResult MaintenancePage()
{
return View();
}
在我的 HomeController 中。
而且我忘了提到维护页面在 Views/Home 文件夹中。
在我的 Global.asax.cs 文件中,在 Application_BeginRequest 中,这是正确的语句,具有正确的路径:
HttpContext.Current.RewritePath("/Home/MaintenancePage");