HOWTO: Useful ASP page to return configurable HTTP Status codes
Sometimes, you just want a simple test page on IIS to do some automated testing of your code that interacts with IIS. Here is another useful one in the series.
I have some negative testing therefore need to have IIS to return 403, 404 or 500. How can I configure each? An automated way would be the best but manual is OK too.
There are a couple of approaches to do this. You can either:
- Configure IIS to go down the actual custom error codepath to generate responses with those status codes
- Make a request to a URL that generates responses with those status codes
The former can be accomplished in the following manner:
- There are many types of 403s. For example, you can configure IIS to:
- Disallow Read permissions and then try to access a resource handled by the Static File Handler.
- Disallow Dir Browsing and make sure no file resource matches DefaultDoc and then make a request to "/"
- Etc... just check out the 403*.htm custom error pages for ideas
- 404 can be generated by making a request to /NotExist.htm
- 500 can be generated by making a request to an ASP page with a syntax error (for example, just remove the %> tag of an ASP page
The latter is easier to configure/use and is shown as a code sample at the end of this blog entry. You just need to copy the ASP page to IIS, make sure ASP is enabled, and make a request to that ASP page with the correct querystring parameter. i.e.
<% DIM status status = Request.QueryString( "status" ) IF NOT IsEmpty( status ) THEN Response.Status = status END IF %>