Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got an IIS6 server that is returning 200 when I have my custom 404 page set (Set to be URL /404.htm).

Reading up on it, it seems that if I use the 'file' option instead, it will return an actual 404 status code.

However, I want to be able to set this for all websites on my server (a few hundred), so I want to be able to use a relative path.

When using IIS Manager, it only allows me to pick an absolute path.

share|improve this question
add comment

1 Answer

Since it's IIS, can you simply drop a file in the root of each website? (would probably be easy with a batch file).

This file would be a web.config file (used in ASP.NET)

The code in the web.config would look like this.

<?xml version="1.0"?>
<configuration>
    <system.web>
        <customErrors mode="On" redirectMode="ResponseRewrite">
            <error statusCode="404" redirect="http://localhost/404.htm" />
        </customErrors>
    </system.web>
</configuration>

Then you make another website in IIS that hosts your 404.htm file, and have it executed at localhost


Alternatively you can create a 404.aspx file and wire it up as your 404 error page (instead of the 404.htm). This file would look something like this.

<%@ Page language="c#" %>
<html>
<head>
   <script language="CS" runat="server">
      void Page_Load(object sender, System.EventArgs e) 
      {
          // here were actually telling the browser that the page is 404 and not 200
          Response.Status = "404 Not Found";
          Response.StatusCode = 404;
      } 
   </script>
   <title>404: Whoops, we lost your file.</title>
</head>
<body>
    <h1>404</h1>
    <div>Oops, the resource you are looking for is unavailable</div>
</body>
</html>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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