views:

480

answers:

2

I'm trying to return a custom 404 page using IIS6. (I have a site that is mostly .shtml pages built using movable type). I have tried it 2 ways:

1) set the 404 error handler in IIS to be type "file" with the path \404.html. This works, but it also means that I can't import the header and footer of my site (hence the .shtml) Trying to point the 404 error handler to 404.shtml results in the default 404 page...i guess IIS can't process shtml files in the 404.

2) set the type to "URL". This works great, except that the response code is no longer 404! Its a 200.

How can I get IIS to respond with a 404 response code with the content of my 404.shtml file?

+1  A: 

Given that it's IIS, adding

<% Response.Status = "404 Not Found" %>

to the top of 404.shtml should change the response code to 404.

I am not on a windows machine so I am unable to test it at the moment to verify.

Update:

I was finally able to run a few tests on a IIS 6. As you mentioned in a comment to my post, an .shtml file does not allow script commands to run. So there are at least two ways to work around this:

  1. Instead of naming your custom 404 handling page 404.shtml, name it 404.asp. The user should never see the actual name of the page so it shouldn't cause any issues. Note that "Active Server Pages" must be set to 'Allowed' in the Web Service Extensions folder of IIS.

  2. Modify the page extension mapping for .shtml to use asp.dll instead of ssinc.dll. You can do this from IIS by selecting the website and viewing Properties -> Home Directory tab -> Configuration -> Mappings tab. Note that this is far from an ideal solution because now all your .shtml files will be processed by asp.dll. This could cause your pages to render more slowly (assuming asp.dll processes files more slowly than ssinc.dll due to greater complexity) and violates the principle of least privilege.

If neither of the options fit your situation, then it may still be possible but the solution isn't immediately obvious to me.

lostriebo
hmmm i thought all you could do in shtml files in IIS was include and exec. i'll try this on monday, thanks
Joel
I was wondering that too when I posted the suggestion, but I thought it was worth mentioning at least. Hopefully it'll work.
lostriebo
thanks, i went the route of using URL /404.asp. This worked reasonably well. Thanks again!
Joel
A: 

In IIS Manager, open the Properties of your Web site (or virtual dir) and go to the Custom Errors tab. There you can set which file is sent in case of each error code, including 404.

Timores
thanks, this is what I am trying though.
Joel
Oops, now I understand your point Nr 1, sorry.Intuitively, I don't that that error pages can be dynamic.
Timores