2011-09-23 110 views
0

我正在嘗試在Application_Error中的全局級別自定義錯誤處理。Asp.net MVC 3查看引擎錯誤

Exception ex = Server.GetLastError(); 
    Server.ClearError(); 
    AssortmentDefinitionLogManager.LogException(ex); 
    Context.RewritePath("/Error/Error"); 
    IHttpHandler httpHandler = new MvcHttpHandler(); 
    httpHandler.ProcessRequest(Context); 

,但我得到這個錯誤

Error Message - The view '~/Views/Shared/Error' or its master was not found or no view engine supports the searched locations. 

我也試過這種

 var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); 
     var redirectUrl = urlHelper.Action("Error", "Error"); 

     Response.Redirect(redirectUrl); 
+0

視圖「Error」是否存在於〜/ Views/Shared /或〜/ Views/Error /目錄中? –

回答

0

創建一個名爲ErrorController控制器和該控制器中創建一個名爲Error一個動作方法返回一個ActionResult (或ViewResult)。

然後在~/Views/Error/下創建一個名爲error.cshtml的視圖。

這將解決您的問題。