2012-02-24 6 views
1

デフォルトでは、MVC3アプリケーションは、404、無効な動詞、ルートが見つからないなどの情報を多く提供します。これは非常に冗長なエラーページです。クライアントはまだ404年代を取得し、それ以外のものは何でも、しかし、この種のものが返されることなく、そのようMVC3にエラーの情報を少なくする方法

はどのように我々は、この動作を変更できますか?エラー時にユーザーへ

<html> 
    <head> 
     <title>The resource cannot be found.</title> 
     <style> 
     body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
     p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} 
     b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} 
     H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } 
     H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } 
     pre {font-family:"Lucida Console";font-size: .9em} 
     .marker {font-weight: bold; color: black;text-decoration: none;} 
     .version {color: gray;} 
     .error {margin-bottom: 10px;} 
     .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } 
     </style> 
    </head> 

    <body bgcolor="white"> 

      <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1> 

      <h2> <i>The resource cannot be found.</i> </h2></span> 

      <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> 

      <b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. &nbsp;Please review the following URL and make sure that it is spelled correctly. 
      <br><br> 

      <b> Requested URL: </b>/Foo<br><br> 

      <hr width=100% size=1 color=silver> 

      <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225 

      </font> 

    </body> 
</html> 
<!-- 
[HttpException]: A public action method &#39;Index&#39; was not found on controller &#39;MySystem.Api.Rest.Controllers.MyController&#39;. 
    at System.Web.Mvc.Controller.HandleUnknownAction(String actionName) 
    at System.Web.Mvc.Controller.ExecuteCore() 
    at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) 
    at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5() 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d() 
    at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) 
    at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) 
    at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) 
    at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 
--> 
+2

設定でカスタムエラーを定義します。 http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx –

答えて

2

を参照してくださいステップ9を参照してください。

デフォルトのMVCテンプレートでカスタムエラーがオンになっています。

これを有効にする方法は小売モードを有効にすることです。これにより、マシン上のすべてのサイトでカスタムエラーが有効になります。

https://kevww.wordpress.com/tag/mvc/

基本的にはちょうどあなたのmachine.configに行くと、そこにそれを設定します。 (例:C:\ WINDOWS \ Microsoft.NET \ Frameworkの\ v4.0.30319 \ CONFIG \ machine.configの)

 
<system.web> <deployment retail="true" /></system.web> 

はまた、あなたのエラー(それらをログ)も自動的にをキャプチャするためにELMAHをインストールします。

http://code.google.com/p/elmah/wiki/MVC

0

あなたが望むものは何でもあなたのコントローラやショーでオーバーライドOnException方法 (つまりなど私たちのプライベートなフレームワーク情報、クラス名を、表示下部にあるものは、特にな)(を含みますカスタムページスタイルなど)。

例えば、小売モードをオンにするには、ここhttp://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html

+0

/foo/bar/whatever/IMadeThisUp /のようなナンセンスルートを入力するとどうなりますか?私は主にこれらのエラーを取得します。 –

1

あなたは、web.configファイルにcompilition debug="false"を設定することができます。

IISでホストされているすべてのウェブサイトのためにこれをしたい場合は、カスタムエラーページを表示したい場合は、web.configファイルでHttpErrors節をオーバーライドすることができますのmachine.config

retail mode=trueを設定することができます。

関連する問題