Asp.net-Mvc

web.config 中的 <customErrors> 在哪裡用於 MVC 應用程序?

  • April 27, 2013

我正在嘗試在我的 MVC 4 應用程序中實現自定義錯誤處理。我不確定我的 web.config&lt;customErrors&gt;應該放在哪裡,以及我需要包含在其中的一般資訊。

&lt;customErrors&gt;進去&lt;system.web&gt;

&lt;configuration&gt;
   &lt;system.web&gt;
       &lt;customErrors mode="RemoteOnly"&gt;
           &lt;error statusCode="500"
                  redirect="~/Error/InternalServer" /&gt;
           &lt;error statusCode="404"
                  redirect="~/Error/NotFound" /&gt;
       &lt;/customErrors&gt;
   &lt;/system.web&gt;
&lt;/configuration&gt;

redirect根據您的路線修改屬性值。您還可以通過向元素添加defaultRedirect屬性來實現包羅萬象的重定向。customErrors有關詳細資訊,請參閱此 MSDN 文章

引用自:https://stackoverflow.com/questions/16251134