2017-12-27 1370 views
0

不能重定向我想重定向到一个维护屏幕时,我们所定义的维护窗口内(开始日期时间和结束日期时间之间)能从应用程序的BeginRequest在第一次请求使用RewritePath

我的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"); 
    } 
} 

如果我开始了我的维护窗外应用程序,然后等到窗口开始日期时间(或简单地更改配置),我重定向到维护屏幕上的一个请求。但是,如果我尝试维护窗口期间启动我的申请,我得到以下错误:

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. 

不知道如何调试这一点,或者我的下一步应该是什么。

编辑:

如果我开始了我的维护窗口内的应用程序,我需要:

HttpContext.Current.RewritePath("Home/MaintenancePage"); 

,使其正常工作。

如果我开始了我的维护窗外申请,然后等待维护窗口开始时间,我需要:

HttpContext.Current.RewritePath("MaintenancePage"); 

,使其正常工作。

EDIT2:

忘了提,我有这样的:

public ActionResult MaintenancePage() 
{ 
    return View(); 
} 

在我的HomeController。

我忘了提及维护页面在Views/Home文件夹中。

+0

99%,您重定向页面维护自身下去。很难肯定地知道你实际重定向到哪里。 –

+0

@Alexi - 不,它不适用于Rewritepath。 – Joe

+0

@Alexi - 'RewritePath'不重定向。因此,它不会生成额外的'BeginRequest'事件。 – Joe

回答

0

在我的Global.asax.cs文件中的Application_BeginRequest,这是正确的说法,用正确的路径:

HttpContext.Current.RewritePath("/Home/MaintenancePage"); 
相关问题