title: Custom 401 page in IIS with ASP.NET
body: <p>I have an internet facing ASP.NET website which I want to secure via Windows Authentication. I set my web.config file as:</p>
  
  <pre><code>&lt;system.web&gt;
   &lt;authentication mode="Windows" /&gt;
   &lt;authorization&gt;
      &lt;allow users="*"/&gt;
      &lt;deny users="?"/&gt;        
   &lt;/authorization&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have then disabled Anonymous Access and enabled Windows Authentication in IIS 7.5.</p>
  
  <p>This results in the prompt box being displayed for my Windows credentials, however clicking 'Cancel' gives me a standard 401 error page. I would like to display a static HTML file in place of this message, however I've not been able to get it working and I've tried a combination of various settings such as:</p>
  
  <pre><code>&lt;httpErrors errorMode="Custom" existingResponse="Replace" lockAllAttributesExcept="errorMode"&gt; &lt;error statusCode="401" prefixLanguageFilePath="c:\inetpub\custerr" path="MyCustom401.htm" /&gt; &lt;/httpErrors&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;customErrors mode="Off" defaultRedirect="ErrorPage.aspx"&gt;
      &lt;error statusCode="401" redirect="MyCustom401.aspx" /&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>What I would like to happen is that anyone entering the correct Windows credentials can carry onto the website as normal, but those with invalid or details to see the custom HTML page.</p>
  
  <p>Can anyone point me in the right direction?</p>
  
  <p>Thanks!</p>