9
如果您在web config中將自定義錯誤設置爲RemoteOnly
- 這是否意味着在錯誤時不會觸發global.asax
-Application_Error
中的MVC應用程序級錯誤事件?如果自定義錯誤已打開,global.asax是否會觸發Application_Error事件?
我剛剛注意到,當我的應用程序發生某種錯誤,並且我正在遠程查看該站點時,沒有記錄任何錯誤。但是,當我訪問服務器上的應用程序併發生相同的錯誤時,會記錄該錯誤。
這是自定義錯誤配置設置:
<customErrors defaultRedirect="/Error/Application" mode="RemoteOnly">
<error statusCode="403" redirect="/error/forbidden"/>
<error statusCode="404" redirect="/error/notfound"/>
<error statusCode="500" redirect="/error/application"/>
</customErrors>
編輯
只是出於對人的興趣 - 我最終完全關閉自定義錯誤,並重定向在Application_Error
處理像這樣:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
// ... log error here
var httpEx = exception as HttpException;
if (httpEx != null && httpEx.GetHttpCode() == 403)
{
Response.Redirect("/youraccount/error/forbidden", true);
}
else if (httpEx != null && httpEx.GetHttpCode() == 404)
{
Response.Redirect("/youraccount/error/notfound", true);
}
else
{
Response.Redirect("/youraccount/error/application", true);
}
}