Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I display custom error pages in Asp.Net Mvc 3?
    primarykey
    data
    text
    <p>I want all 401 errors to be be redirected to a custom error page. I have initially setup the following entry in my web.config. </p> <pre><code>&lt;customErrors defaultRedirect="ErrorPage.aspx" mode="On"&gt; &lt;error statusCode="401" redirect="~/Views/Shared/AccessDenied.aspx" /&gt; &lt;/customErrors&gt; </code></pre> <p>When using IIS Express I receive the stock IIS Express 401 error page.</p> <p>In the event when I do not use IIS Express a blank page is returned. Using Google Chrome's Network tab to inspect the response, I see that while the page is blank a 401 status is returned in the headers</p> <p>What I have tried thus far is using suggestions from <a href="https://stackoverflow.com/questions/2480006/what-is-the-difference-between-customerrors-and-httperrors">this SO answer</a> since I am using IIS Express but to no avail. I have tried using a combination <code>&lt;custom errors&gt;</code> and <code>&lt;httpErrors&gt;</code> with no luck - the standard error or blank page is still displayed. </p> <p>The <code>httpErrors</code> section looks like this at the moment based on <a href="https://serverfault.com/questions/123729/iis-is-overriding-my-response-content-if-i-manually-set-the-response-statuscode/124074#124074">the link</a> from the <a href="https://stackoverflow.com/questions/2480006/what-is-the-difference-between-customerrors-and-httperrors">above SO question</a> ( I also found another very <a href="https://stackoverflow.com/questions/6512904/how-to-create-custom-404-error-pages-in-asp-net-mvc-3">promising answer</a> however no luck - blank response) </p> <pre><code>&lt;system.webServer&gt; &lt;httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough" &gt; &lt;remove statusCode="401" /&gt; &lt;error statusCode="401" path="/Views/Shared/AccessDenied.htm" /&gt; &lt;/httpErrors&gt; &lt;!-- &lt;httpErrors errorMode="Custom" existingResponse="PassThrough" defaultResponseMode="ExecuteURL"&gt; &lt;remove statusCode="401" /&gt; &lt;error statusCode="401" path="~/Views/Shared/AccessDenied.htm" responseMode="File" /&gt; &lt;/httpErrors&gt; --&gt; &lt;/system.webServer&gt; </code></pre> <p>I have even modified the <code>applicationhost.config</code> file and modified <code>&lt;httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath"&gt;</code> to <code>&lt;httpErrors lockAttributes="allowAbsolutePathsWhenDelegated"&gt;</code> based on information from <a href="http://www.iis.net/ConfigReference/system.webServer/httpErrors" rel="nofollow noreferrer">iis.net</a>. During the course of my endeavours I also managed to stumbled upon this error as described in <a href="https://stackoverflow.com/questions/6390886/500-19-error-with-iis7-5">another SO question</a>. </p> <p>How do I display custom error pages in Asp.Net Mvc 3?</p> <p><strong><em>Additional info</em></strong></p> <p>The following controller actions have been decorated with the <code>Authorise</code> attribute for a specific user.</p> <pre><code>[HttpGet] [Authorize(Users = "domain\\userXYZ")] public ActionResult Edit() { return GetSettings(); } [HttpPost] [Authorize(Users = "domain\\userXYZ")] public ActionResult Edit(ConfigurationModel model, IList&lt;Shift&gt; shifts) { var temp = model; model.ConfiguredShifts = shifts; EsgConsole config = new EsgConsole(); config.UpdateConfiguration(model.ToDictionary()); return RedirectToAction("Index"); } </code></pre>
    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.
 

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