2012-01-14 7 views
0

アプリケーションから404エラーが発生します。
404エラーのページは/ErrorPages/Error_404.cshtml です。このファイルにはHTMLコードしかありません。正常に動作します。
しかし、私はいくつかのかみそりのコードを追加すると、ブラウザに設定エラーがスローされます。
私は例えばレイアウトまたは一部@Html.ActionLink(...
これは誤りであるを追加します。cshtml(エラー)ページのカミソリコード

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.

Details: To enable the details of this specific error message to be viewable on the local server machine, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".

これは私が404を生成する方法である:

public ActionResult Search(string searchTerm) 
{ 
if (city == null) 
      { 
       throw new HttpException(404, "Some description");    
      } 
      else 
      { 
       return RedirectToAction("Index", "Home", new 
       {... 
      } 
} 

とNOかみそりコードは、それがエラーページではありませんうまくいけば、私は上からメッセージを受け取ります。
私は、Web設定「モード=オフ」に設定すると、私はエラーメッセージが表示されます。これは、Web構成

<customErrors mode="Off"> 
     <error statusCode="404" redirect="\ErrorPages\Error_cp404.cshtml" /> 
    </customErrors> 
+2

は、web.configファイルでオフにカスタムエラーを設定し、私達に実際のエラーメッセージを伝える:

また、あなたがIIS7 +で実行している場合は、次を追加する必要があるかもしれません。 – Judo

+0

@Judoカスタムエラーをオフにすると、システムはエラーメッセージページを表示せず、デフォルトの例外スタックを表示します。 1110、あなたはそのページをデバッグし、実際のエラーを表示してください – archil

+0

あなたのコメントに基づいて私の質問が更新されました。 – 1110

答えて

4

からの値である

Description: 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. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /CityPage/Navigation/Search

あなたは.cshtmlページをレンダリングしようとするべきではありません直接。それらは剃刀の意見です。 ASP.NETでは、MVCビューはコントローラアクションを通じて提供されます。

ので:

あなたはErrorsControllerを持っている可能性が
<error statusCode="404" redirect="Errors/Error404" /> 

public class ErrorsController: Controller 
{ 
    public ActionResult Error404() 
    { 
     return View(); 
    } 
} 

また、エラーを処理する別の方法のためfollowing answerをチェックアウトします。

<system.webServer> 
    ... 
    <httpErrors errorMode="Detailed" /> 
</system.webServer> 
+0

リンクのあなたの答えは解決問題を提供しました。ありがとう。私は、かすかなページはコントローラクラスなしで動作できると考えられていました。 – 1110

関連する問題