在ASP.Net URL中禁用aspxerrorpath参数

Bha*_*hav 2 asp.net web-config custom-error-pages custom-errors

我已将以下内容添加到我的web.config中,以将用户重定向到自定义错误页面而不是默认页面

'/'应用程序中的服务器错误.

错误信息.

用户被重定向到 error.html?aspxerrorpath=/paymentservices.svc

有没有办法删除该?aspxerrorpath=/paymentservices.svc部分?

web.config中:

<system.web>
    <customErrors defaultRedirect="~/ErrorPages/error.html"
  mode="On" xdt:Transform="Replace">
    <error statusCode="500" redirect="~/ErrorPages/error.html"/>
    <error statusCode="404" redirect="~/ErrorPages/error.html"/>
    </customErrors>
</system.web>
Run Code Online (Sandbox Code Playgroud)

小智 5

一种便宜的方法是将您自己的查询字符串添加到错误的末尾 - 它应该覆盖"默认"字符串.即使是空字符串也应该有用.

<error statusCode="500" redirect="~/ErrorPages/error.html?"/>

或者您可以将自己的错误处理添加到Global.ascx中的Application_Error