2011-08-01 78 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