Redirect 401 in web.config or global.asax EndRequest event?
<p>I have a site that is using forms authentication, but the login url is actually a page ("WinLogin.aspx") that is set to use windows authentication.  That way, if the user is on our network, WinLogin.aspx captures their domain login and they can continue on into the application without having to reenter their username and password.  But if they are not logged into the domain, WinLogin.aspx gives a 401 error, which a browser would normally interpret by asking the user for their username and password to check against the domain server.<p>
I want to redirect those 401 errors to my own custom page that gets that username and password, so I can do a true forms authentication, because some of the accounts in my application do not have a corresponding domain account.<p>
I can do the rerouting of the 401 error in the web.config file like this:</p>

<pre><code>    &lt;httpErrors errorMode="Custom"&gt;
        &lt;error statusCode="401" path="/Redirect401.aspx" /&gt;
    &lt;/httpErrors&gt;
</code></pre>

<p>Or, I can do it with code in the global.asax end request handler like this:</p>

<pre><code>void Application_EndRequest(object sender, System.EventArgs e)
{
    if (((Response.StatusCode == 401) &amp;&amp; (Request.IsAuthenticated == true)))
    {
        Response.ClearContent();
        Response.Redirect("~/Redirect401.aspx");
    }
}
</code></pre>

<p>Is there any reason to prefer either method?</p>