要自定义404处理和基于托pipe公司的build议,我们正在使用以下web.config设置。 但是,我们很快意识到,通过这种configuration,任何页面错误(500错误)也会被redirect到这个自定义错误页面。 我怎样才能修改这个configuration文件,所以我们可以继续处理404自定义文件,同时仍然能够查看页面错误?
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.webServer> <httpErrors errorMode="DetailedLocalOnly" defaultPath="/Custom404.html" defaultResponseMode="ExecuteURL"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="/Custom404.html" responseMode="ExecuteURL" /> </httpErrors> </system.webServer> <system.web> <customErrors mode="On"> <error statusCode="404" redirect="/Custom404.html" /> </customErrors> </system.web> </configuration>
尝试这个 –
<configuration> <system.webServer> <httpErrors errorMode="Custom" defaultResponseMode="File" > <remove statusCode="404" /> <remove statusCode="500" /> <error statusCode="404" path="404.html" /> <error statusCode="500" path="500.html" /> </httpErrors> </system.webServer> </configuration>
404错误页面是404.html,它位于我的根目录,同样也是500页
我在IIS 7.5中发现了很多经典ASP的复杂变通办法,用于处理特定错误代码的IIS 6types的自定义error handling,通常是404。我希望这可以帮助那些偶然发现的人。
我正在运行IIS 7.5 R2,但我认为这适用于一般的IIS 7。
如果你的web.config文件中有这个:
<customErrors mode="On">
…在IISpipe理器中,您可能select了“错误页面”下的“编辑function”来更改“编辑错误页面设置”面板上的function。 如果将其更改为“自定义错误页面”(customErrors mode =“On”),则必须设置处理每个错误编号。 所以不要这样做。
所有你需要做的是右键单击你想要处理的错误号码,然后select编辑。 在那里,您可以指向您创build的自定义错误页面或redirect到一个URL。 而不是创build一个自定义的错误页面,你必须记住要更新当您的网站devise或菜单更改时,我总是build议redirect到主页,并添加一些东西像查询string?syserror,然后您可以从主页处理。 我的技术是在主页脚本中检查这一点,并popup一个友好的消息,让他们知道他们的网页没有被发现,他们被引导到主页。
你的web.config文件看起来像这样:
<httpErrors> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="http://yoursite.com/index.asp?syserror" responseMode="Redirect" /> </httpErrors>
我还build议您不要在生产网站上启用详细的错误消息作为安全防范,即使是本地的。 只需查看系统日志中的详细信息。
只是我的2美分,希望它可以帮助,请让我知道,如果你认为我在这里的任何东西不正确。
只需为500个错误添加另一个值。
<customErrors mode="On"> <error statusCode="404" redirect="/Custom404.html" /> <error statusCode="500" redirect="/Custom500.html" /> </customErrors>
传统的ASP默认情况下不通过IIS7中的错误。 要为网站启用该function,请从命令行运行以下命令,确保将{sitename}replace为您的名称网站:
c:\ windows \ system32 \ inetsrv \ appcmd.exe set config“{sitename}”-section:system.webServer / httpErrors / existingResponse:“PassThrough”/ commit:apphost
此外,请确保closures IIS友好的错误。 他们真的不友善。