2012-03-30 22 views
0

我有mvc 3應用程序,當一個標準通用拋出新的異常拋出代碼時,從Views \ Shared \ error.cshtml中顯示錯誤頁面。這是通過簡單的設置<customErrors mode="On"/>.(這正如預期的及如需要)MVC應用程序FaultException拋出如何得到顯示錯誤頁面

使用在中間層,當這些服務產生的FaultException MVC WCF服務的應用程序沒有顯示出來它顯示的信息的錯誤頁面做Web服務在屏幕上調用用戶。我想要做的就是處理我的代碼中的錯誤,並向用戶顯示Error.cshtml。我試圖改變全球asax,但這劑量的工作。

protected void Application_Error(object sender, EventArgs e) 
    { 
     Exception exception = Server.GetLastError(); 
     if (exception.GetType() == typeof(FaultException)) 
     { 
     throw new Exception("There was a fault exception that i do not want to show details of to user."); 

     } 
    } 

回答

0

嘗試創建一個ErrorController作爲asp.net MVC將盡力解決您指定在web.config中爲{}控制器的鏈接/ {}查看,除非你指定它忽略頁面。另外,您可能想要應用一個屬性來處理異常。

0

您還可以創建一個錯誤控制器/視圖並在catch塊重定向到您的選擇

try 
    { 
     foo.bar()  
    } 
    catch(SpecificException) 
    { 
     RedirectToAction("500", "Error"); 
    } 
的自定義錯誤頁
相關問題