2017-12-27 1638 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"); 
相關問題