Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe I'm missing something, but MVC has a default global <code>ErrorHandlerAttribute</code> that uses custom errors. This is explained quite well <a href="http://www.dotneat.net/2011/04/12/ErrorHandlingInASPNETMVC3.aspx" rel="noreferrer">here</a>. </p> <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } </code></pre> <p>All you need to do is turn on <code>custom errors</code> in the config, and then setup custom error redirects, preferably to a static <code>HTML</code> file (in case there's errors with the app). </p> <pre><code>&lt;customErrors mode="On" defaultRedirect="errors.htm"&gt; &lt;error statusCode="404" redirect="errors404.htm"/&gt; &lt;/customErrors&gt; </code></pre> <p>If you prefer could also point to a custom <code>Controller</code> to display the errors. In the following example I've just used the default routing to a <code>Controller</code> named <code>Error</code>, with an action called <code>Index</code>, and string parameter named <code>id</code> (to receive the errorcode). You could of course use any routing you desire. Your example isn't working because you are trying to link directly into the <code>Views</code> directory without going via a <code>Controller</code>. MVC .NET doesn't serve requests to the <code>Views</code> folder directly.</p> <pre><code>&lt;customErrors mode="On" defaultRedirect="/error/index/500"&gt; &lt;error statusCode="404" redirect="/error/index/404"/&gt; &lt;/customErrors&gt; </code></pre> <p>The <a href="http://weblogs.asp.net/fredriknormen/archive/2007/11/22/asp-net-mvc-framework-handling-exception-by-using-an-attribute.aspx" rel="noreferrer">ErrorHandlerAttribute</a> can also be used extensively with <code>Controllers/Actions</code> to redirect errors to named <code>Views</code> related to the <code>Controller</code>. For example to show the <code>View</code> named <code>MyArgumentError</code> when a exception of type <code>ArgumentException</code> occurs you could use:</p> <pre><code>[ControllerAction,ExceptionHandler("MyArgumentError",typeof(ArgumentException))] public void Index() { // some code that could throw ArgumentExcepton } </code></pre> <p>Of course another option is to update the stock <code>Error</code> page in <code>Shared</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload