我有我的自定义404页面设置(设置为URL / 404.htm)返回200的IIS6服务器。
阅读它,似乎如果我使用“文件”选项,它会返回一个实际的404状态码。
但是,我希望能够为我的服务器上的所有网站(几百)设置此,所以我想能够使用相对path。
当使用IISpipe理器时,它只允许我select绝对path。
由于它是IIS,你可以简单地在每个网站的根目录下放一个文件吗? (使用batch file可能会很容易)。
这个文件将是一个web.config文件(在ASP.NET中使用)
web.config中的代码看起来像这样。
<?xml version="1.0"?> <configuration> <system.web> <customErrors mode="On" redirectMode="ResponseRewrite"> <error statusCode="404" redirect="http://localhost/404.htm" /> </customErrors> </system.web> </configuration>
然后,您在IIS中创build另一个托pipe您的404.htm文件的网站,并在localhost执行404.htm文件
或者,您可以创build一个404.aspx文件并将其连接为404错误页面(而不是404.htm )。 这个文件看起来像这样。
<%@ 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>