title: Trouble getting ASP.NET MVC app to redirect to error page for unauthorized users
body: <p>I've got the following set up in the web.config of my ASP.NET MVC application:</p>
  <pre><code>&lt;authentication mode=&quot;Windows&quot; /&gt;
  &lt;authorization&gt;
      &lt;allow roles=&quot;MySecurityGroup&quot;/&gt;
      &lt;deny users=&quot;*&quot;/&gt;
  &lt;/authorization&gt;
  &lt;customErrors mode=&quot;On&quot; defaultRedirect=&quot;Error.aspx&quot;&gt;
      &lt;error statusCode=&quot;401&quot; redirect=&quot;Help.aspx&quot;/&gt;
  &lt;/customErrors&gt;
  </code></pre>
  <p>Everything works fine if you are in MySecurityGroup, but if you're not, you are not redirected to either Error.aspx or Help.aspx. (Note that Error.aspx lives in Views\Shared while Help.aspx is in Views\Home.) All you get is the default error:</p>
  <blockquote>
  <p>Server Error in '/' Application.</p>
  <p>Access is denied.</p>
  <p>Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.</p>
  <p>Error message 401.2.: Unauthorized: Logon failed due to server configuration.  Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.  Contact the Web server's administrator for additional assistance.</p>
  </blockquote>
  <p>What am I doing wrong?</p>
  <p><strong>UPDATE:</strong> Now my web.config is set up like this, and it's still not working:</p>
  <pre><code>&lt;system.web&gt;
      &lt;customErrors mode=&quot;On&quot; defaultRedirect=&quot;Help.aspx&quot;&gt;
      &lt;/customErrors&gt;
  &lt;/system.web&gt;
  
  &lt;location path=&quot;&quot;&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow roles=&quot;MySecurityGroup&quot;/&gt;
              &lt;deny users=&quot;*&quot;/&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  
  &lt;location path=&quot;Help&quot;&gt;
      &lt;system.web&gt;
          &lt;authorization&gt;
              &lt;allow users=&quot;*&quot;/&gt;
          &lt;/authorization&gt;
      &lt;/system.web&gt;
  &lt;/location&gt;
  </code></pre>
  <p>Note that I can navigate to MyApp/Help just fine and am correctly banned from the rest of the site, but it never redirects to the Help page automatically.</p>