我在我的視圖中設置了/shared/error.cshtml頁面以顯示更友好的錯誤消息。但是當用戶遇到錯誤時它不會顯示。未顯示MVC自定義錯誤
我的web.config文件有:
<system.web>
<customErrors mode="On" />
和我的global.asax.cs有:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
但錯誤消息我得到的仍然是基本的
`Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".`
我錯過了什麼?
你究竟想達到什麼目的?如果您不指定自定義錯誤頁面,將CustomErrors設置爲On沒有意義?基本上它說,發生錯誤,並顯示自定義錯誤頁面的錯誤... – SmartDev 2014-09-30 09:50:56
我希望它去共享佈局中指定的error.cshtml。它在默認情況下在創建MVC應用程序時執行此操作,但是我們從頭開始構建,因此我不知道如何執行 – LiamHT 2014-09-30 10:03:32
您應該有一個ErrorController,其中包含顯示此視圖的操作。並且該操作應具有以下注釋:[HandleError(View =「Error」,ExceptionType = typeof(Exception))] – SmartDev 2014-09-30 11:03:07