Custom HTTP Error Handling in IIS

Sometimes you need very precise control over the HTTP error responses returned by IIS 7. IIS 7 provides methods to hook into the response stream in the integrated pipeline and many IIS 7 settings are actually contained in configuration files like Web.config and machine.config.

If you have custom text you want to return for an HTTP status code then don’t forget about the existingResponse attribute of the httpErrors element. This attribute tells the custom error module what to do when the response text is not blank. You can choose to replace the custom text (existingResponse=”Replace”), pass the text through (existingResponse=”PassThrough”) or automatically decide the right thing to do (existingResponse=”Auto”).

The following Web.config snippet for an IIS 7 web application shows how to pass through text from a custom error module running in the web application in response to HTTP 401.1 errors.

[sourcecode language=”xml”] <?xml version=”1.0″ encoding=”UTF-8″?>
<httpErrors errorMode=”Custom” existingResponse=”PassThrough”>
<remove statusCode=”401″ subStatusCode=”1″ />

Comments are closed.

Sign in
Forgot password?
Sign up

(*) Required fields

I agree with OptimaSales Terms & Privacy Policy