網站自定義錯誤頁面的設置,大家應該都知道它的重要性……不多說,下面帶大家一步步在IIS下設置網站自定義錯誤頁面……
1、首先進入你的網站主頁,找到【錯誤頁】(注意是IIS下的錯誤頁不是.NET錯誤頁),雙擊【錯誤頁】
2、這樣就進入了錯誤頁面,點擊【編輯】或者雙擊狀態代碼行,打開“編輯自定義錯誤頁面”
3、填寫狀態碼,響應操作處選擇第二項【在此網站上執行】,輸入URL
4、查看錯誤頁面相對根目錄的位置,按照示例填寫就可以的。然后依次設置其它頁面
5、當然還可以通過修改配置文件(web.config)來設置自定義頁面,它和上面的配置是對應的。
1 <?xml version="1.0" encoding="UTF-8"?>
2 <configuration>
3 <system.webServer>
4 <httpErrors errorMode="Custom">
5 <remove statusCode="502" subStatusCode="-1" />
6 <remove statusCode="501" subStatusCode="-1" />
7 <remove statusCode="500" subStatusCode="-1" />
8 <remove statusCode="412" subStatusCode="-1" />
9 <remove statusCode="406" subStatusCode="-1" />
10 <remove statusCode="405" subStatusCode="-1" />
11 <remove statusCode="403" subStatusCode="-1" />
12 <remove statusCode="401" subStatusCode="-1" />
13 <remove statusCode="404" subStatusCode="-1" />
14 <error statusCode="401" prefixLanguageFilePath="" path="/ErrorPages/401.html" responseMode="ExecuteURL" />
15 <error statusCode="404" prefixLanguageFilePath="" path="/ErrorPages/404.html" responseMode="ExecuteURL" />
16 <error statusCode="403" prefixLanguageFilePath="" path="/ErrorPages/403.html" responseMode="ExecuteURL" />
17 <error statusCode="405" prefixLanguageFilePath="" path="/ErrorPages/405.html" responseMode="ExecuteURL" />
18 <error statusCode="406" prefixLanguageFilePath="" path="/ErrorPages/406.html" responseMode="ExecuteURL" />
19 <error statusCode="412" prefixLanguageFilePath="" path="/ErrorPages/412.html" responseMode="ExecuteURL" />
20 <error statusCode="500" prefixLanguageFilePath="" path="/ErrorPages/500.html" responseMode="ExecuteURL" />
21 <error statusCode="501" prefixLanguageFilePath="" path="/ErrorPages/501.html" responseMode="ExecuteURL" />
22 <error statusCode="502" prefixLanguageFilePath="" path="/ErrorPages/502.html" responseMode="ExecuteURL" />
23 <error statusCode="503" prefixLanguageFilePath="" path="/ErrorPages/503.html" responseMode="ExecuteURL" />
24 </httpErrors>
25 </system.webServer>
26 </configuration>
<error statusCode="404" prefixLanguageFilePath="" path="/ErrorPages/404.html" responseMode="ExecuteURL" />
有兩個重要的點:狀態碼(statusCode)和路徑(path),填寫的時候要細心。