title: MVC Windows Authentication prompts for windows credentials and ignores custom error configuration
body: <p>In a web application, that runs MVC4 on an IIS7.5 server (integrated pipeline) using Windows Authentication and a custom role provider, I want to display a custom error page on 401 not authorized errors, if somebody tries to access something they do not have permissions for. </p>
  
  <p>When I debug locally in Visual Studio, the error pages are displayed correctly, and my nice, custom "Not authorized" page shows up as expected.</p>
  
  <p>Deploy to the server - and I get the windows prompt.</p>
  
  <p><img src="https://i.stack.imgur.com/lwXIr.png" alt="enter image description here"></p>
  
  <p>Here are the (I think) relevant parts of web.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;authentication mode="Windows" /&gt;
      &lt;authorization&gt;
        &lt;deny users="?"/&gt;
      &lt;/authorization&gt;
      &lt;roleManager enabled="true" defaultProvider="MyCustomRoleProvider"&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="FimOpsAccessControlRoleProvider" type="Namespace.MyCustomRoleProvider" /&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
      &lt;customErrors mode="On" defaultRedirect="~/Error"&gt;
        &lt;error redirect="~/Error/Error401" statusCode="401" /&gt;
      &lt;/customErrors&gt; 
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
        &lt;remove statusCode="401" /&gt;
        &lt;error statusCode="401" path="/error/error401" responseMode="ExecuteURL" /&gt;
      &lt;/httpErrors&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>On the production server, I am able to browse to /error/error401 just fine - and I have also tried replacing that with a static html file and pointing to that, with the same result.</p>
  
  <p>I have tried static error pages, doing stuff in global.asax Application_OnError, every thinkable combination of configurations I could think of in web.config - but with no luck. I have found at least 10 other posts on SO that deals with this problem, but none of the solutions work for me - maybe due to differences in versions, I do not know.</p>
  
  <p>Why is this happening - and how do I get around it?</p>