開発中またはサーバー上でローカルに有用な情報を提供する場合は YSOD を表示したいが、それ以外の場合は半一般的なページを表示したい。web.config でdefaultRedirect
アプリケーションの構成タグの属性を設定できることはわかっていますが、少し処理を行って、もう少し優れた情報を含むページを生成したいと考えています。<customErrors>
すべてのコントローラーは、OnException をオーバーライドした中央の BaseController クラスから継承します (基本的には次のようにします)。
protected override void OnException(ExceptionContext filterContext) {
//if something really bad happened and we get inside this if,
//just let the YSOD appear because there isn't anything we can do
if (filterContext == null)
return;
LogException(filterContext.Exception);
//insert answer for question here:
if (FigureOutIfDetailedYsodWouldBeDisplayed(filterContext))
return;
//what to actually do for end users
filterContext.ExceptionHandled = true;
filterContext.Result = View("ErrorPage", GetErrorModel(filterContext));
}
どのように実装すればよいですかFigureOutIfDetailedYsodWouldBeDisplayed
(答えはコードである必要はありません。正しい方向へのポインターで十分です)。私の現在の実装では、「//localhost」の存在について生の URL をチェックしますが、この解決策は不器用に感じられ、常に機能するとは限りません (たとえば、開発者が localhost 以外のものを入力するホスト エントリを持っている場合: 私たちの要件)以前はあったアプリ)。