Web設定でRemoteOnly
にカスタムエラーが設定されている場合、MVCのアプリケーションレベルエラーイベントglobal.asax
-Application_Error
がエラーで起動しないことを意味しますか?カスタムエラーがオンになっている場合、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>
EDIT
- 私は完全にカスタムエラーをオフにし、そのよう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);
}
}