6

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?

2 Answers 2

7

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.

4
  • hmmm i thought all you could do in shtml files in IIS was include and exec. i'll try this on monday, thanks
    – Joel
    Feb 28, 2010 at 15:06
  • I was wondering that too when I posted the suggestion, but I thought it was worth mentioning at least. Hopefully it'll work.
    – lostriebo
    Feb 28, 2010 at 23:13
  • thanks, i went the route of using URL /404.asp. This worked reasonably well. Thanks again!
    – Joel
    Mar 19, 2010 at 20:51
  • I am running Coldfusion. I've read elsewhere that I should be able to return a cfm page (rather than html/asp) but when I try to run a cfm page I get a connection reset. This method works for me, but I'd like to be able to access CF stuff in my page. Any idea why the connection would get reset using the URL method of a 404?
    – Leeish
    Jan 15, 2013 at 22:52
0

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.

1
  • Oops, now I understand your point Nr 1, sorry. Intuitively, I don't that that error pages can be dynamic.
    – Timores
    Feb 28, 2010 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.