私のアプリケーションにカスタムエラー処理が定義されています。リソースが見つからない場合、正しい「NotFound」ビューがレンダリングされます。無制限の例外が発生すると、 'ServerError'ビューがレンダリングされます。MVC3エラー処理 - 「エラー」というビューを使用します。
私が直面している問題は、自分のアプリケーションが 'エラー'というビューを見つけようとしているのに、見つからないということです。私はカスタムエラーが発生したときにこの例外がスローされます:
「ビュー 『エラー』またはそのマスターが見つからなかったか、全くビュー・エンジンは、検索場所をサポートしていない次の場所が検索された:。...」私は、ロギングを行うのApplication_Errorイベントハンドラを持って
を未処理の例外のうち、
protected void Application_Error(Object sender, EventArgs e)
{
Exception lastEx = Server.GetLastError();
// Attempt to Log the error
try
{
Utils.Logger.Error(lastEx);
}
catch (Exception loggingEx)
{
// Try and write the original ex to the Trace
Utils.TryTrace(lastEx.Message);
// Try and write the logging exception to the Trace
Utils.TryTrace(loggingEx.Message);
}
}
は私がのcustomErrorsは、「オン」になっている私のweb.configファイルで:
<customErrors mode="On" defaultRedirect="blah">
<error statusCode="404" redirect="dee"/>
<error statusCode="500" redirect="blah"/>
</customErrors>
そして、私は上記のweb.configファイルで定義されたリダイレクトに対応して、私のGlobal.asax.cs RegisterRoutes方法で定義されたルートを持っている:
をroutes.MapRoute(
"Error - 404",
"dee",
new { controller = "Error", action = "NotFound" }
);
routes.MapRoute(
"ServerError", // When this route is matched we want minimal error info displayed
"blah",
new { controller = "Error", action = "ServerError" }
);
私はOnActionExecutedルーチンが含まれているBaseControllerを持っている:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
Logger.Info(String.Format(Constants.LOG_ACTION_EXECUTED, filterContext.Controller.ToString(), filterContext.ActionDescriptor.ActionName));
// Log any exceptions
if (filterContext.Exception != null)
{
Stack<string> messages = new Stack<string>();
Exception current = filterContext.Exception;
messages.Push(current.Message);
while (current.InnerException != null)
{
messages.Push(current.InnerException.Message);
current = current.InnerException;
}
StringBuilder result = new StringBuilder();
while (messages.Count != 0)
{
result.Append(messages.Pop());
string nextline = messages.Count > 0 ? "OUTER EXCEPTION " + messages.Count + ": " : "";
result.Append(Environment.NewLine);
}
Logger.Error(result.ToString());
}
base.OnActionExecuted(filterContext);
}
Frameworkはでレンダリングするためにビューを定義することをどこかにあります未処理例外のイベント?
私のカスタムエラー処理ルーチンは、フレームワークがもはや 'エラー'ビューを見つけることを期待しないようにする最後のステップを欠いていますか?
Eranga:これはかなり問題ではありませんでしたが、下記のような解決策を見つけることができました - ありがとう!ありがとう! – JTech
ありがとう!それは私のためだった。新しくなった人の中には、新しいテンプレートでは、これはApp_StartフォルダのFilterConfig.csにあります。 –