2013-06-19 30 views

回答

3

您需要處理服務器錯誤代碼爲404。有一個大量的例子在網上(onetwothree),但總之,你可以在下面的部分web.config中做到這一點:

<customErrors mode="On" defaultRedirect="~/Error.html"> 
    <error statusCode="404" redirect="~/Error404.html"/> 
</customErrors> 

其中~/Error.html~/Error404.html是一般性的錯誤頁面,頁面中的「資源不能被發現」的情況。

+0

我想你的解決方案,但我肯定錯過了什麼。你介意看看http://stackoverflow.com/questions/25798775/web-config-not-forwarding-to-404-error-page-on-non-aspx-pages。謝謝 – JGallardo

1

看看在web.config架構the MSDN documentation page for the customErrors element - 提供的例子是這樣的:

<configuration> 
    <system.web> 
    <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly"> 
     <error statusCode="500" redirect="InternalError.htm"/> 
    </customErrors> 
    </system.web> 
</configuration> 
2

添加上述您webconfig

<configuration> 
<system.web> 
<customErrors mode="RemoteOnly" 
    defaultRedirect="~/ErrorPages/Error.aspx"> 
    <error statusCode="404" redirect="~/default.aspx"/> 
    </customErrors> 
</system.web> 

相關問題