http://localhost:56472/test.
抛出丑陋的黄色 ASP.NET 错误消息 - The Resource Cannot be Found
.
我如何捕获此请求和
- 防止丑陋的黄色
- 从请求中删除时间段并重定向?
我Global.asax
里确实有这个:
protected void Application_Error(object sender, EventArgs e) {
// Do whatever you want to do with the error
}
但是错误没有被抓住。 在这里捕获了正常的 404,我成功重定向到我的自定义错误页面。
我正在部署到 Azure PaaS,因此对 IIS 的控制不多。
更新:我尝试重写:
<rule name="Strip Periods" stopProcessing="true">
<match url="^(.*[^.])(.+)$" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^site.com$" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://www.site.com/{R:1}" />
</rule>
您需要两个步骤才能执行此操作。 首先,使用重写规则来处理重定向:
<rule name="RemoveTrailingDot" stopProcessing="true">
<match url="(.*).+$" />
<action type="Redirect" url="{R:1}" />
</rule>
其次,以下指令(在此相关答案中找到)
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
</system.web>
对相关答案的评论表明它并不总是有效,但它在 Windows 10 上的 IIS 上对我有用。