2011-08-01 72 views
0

我正在尝试为404错误提供自定义重定向页面。目前,主机服务器可能存在一个不同的错误页面,我的web.config文件位于下方。当我注释掉customError标签时,主机服务器的默认页面显示出来,我想将其更改为自定义页面“404.html”。当我取消注释时,它可能会尝试覆盖默认值,但会给出内部服务器错误!将404重定向页面从默认页面更改为自定义页面。

<?xml version="1.0" encoding="UTF-8"?> 

    Please refer to machine.config.comments for a description and 
    the default values of each configuration section. 

    For a full documentation of the schema please refer to 
    http://go.microsoft.com/fwlink/?LinkId=42127 

    To improve performance, machine.config should contain only those 
    settings that differ from their defaults. 

<configuration> 
    <system.webServer> 
     <customErrors mode="On"> 
      <error statusCode="404" redirect="/404.html" /> 
     </customErrors> 
     <!--<httpErrors> 
     <remove statusCode="404" subStatusCode="-1" />     
     <error statusCode="404" path="/404.html" responseMode="ExecuteURL" />   
     </httpErrors>-->  
     <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 
+0

它是集成/管道模式的东西吗? – nikhil

回答

1

404声明不会在标签的customErrors走,这里是你应该需要什么:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
     <httpErrors errorMode="DetailedLocalOnly"> 
      <remove statusCode="404" subStatusCode="-1" /> 
      <error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" /> 
     </httpErrors> 
    </system.webServer> 
</configuration> 

尝试设置你的web.config到这一点,看看它的工作原理,在标签的customErrors是更多的.NET页面比传统的ASP,即使是经典的500:100httpErrors部分中声明,而不是在CustomErrors中声明。

这是从一个已知的工作web.config中取出的,删除了不相关的位。您可以像使用ExecuteURL一样将它发送到ASP页面,这意味着您可以巧妙地处理404页面,例如重定向或提供搜索结果页面。

+0

工作谢谢理查! – nikhil