views:

247

answers:

1

I keep coming across web examples of setting up custom error pages, and people do things like this:

<customErrors mode="RemoteOnly" defaultRedirect="GeneralError.aspx">
    <error statusCode="401.2" redirect="4012Error.htm"/>
</customErrors>

I know that a 401.2 redirect has its own set of headaches, but IIS isn't complaining about that. This is what it's giving me when I browse my site:

Parser Error Message: The value of the property 'statusCode' cannot be parsed. The error is: 401.2 is not a valid value for Int32.

If I change it to "401", it works fine. Even the Intellisense complains that statusCode needs to be Int32.

How are people using the subcodes? I sure can't!

Many thanks!

A: 

From http://msdn.microsoft.com/en-us/library/aa478979.aspx

Basic authentication under Windows, by default, will allow three attempts at a correct user name and password combination. If all three fail, it will send an HTTP 401.2 Unauthorized error. Since basic authentication is performed by IIS and not by ASP.NET, you cannot create customized error pages since ASP.NET will never have a chance to see the request.

Can you place some code in your global.asax file to catch these types of errors? You just need to be aware that the global.asax file executes on each page request, so make sure you have valid checks to prevent redirection prior to accessing the default and login pages.

You can also just go into IIS and change the default error page to point to your URL for this error for your web site.

Jim W
This is the guide I'm using for showing an error for a 401.2:http://www.flimflan.com/blog/HttpModuleToAllowACustomErrorPageFor4012AccessDeniedInASPNET.aspxIt puts an httphandler in, which I believe forces IIS to process my customError.I changed the default error page in IIS, but since I have graphics and a CSS include on my error page, the page doesn't load properly. Only the HTML is shown - the graphics and CSS get a 401.2 error and they do not show up.I saw a few posts where people complained that global.asax wasn't working for them, which is why I was trying the httpmodule approach.
TimH