如何防止“ aspxerrorpath”作为查询字符串传递到ASP.NET自定义错误页面 [英] How to prevent "aspxerrorpath" being passed as a query string to ASP.NET custom error pages

查看:171
本文介绍了如何防止“ aspxerrorpath”作为查询字符串传递到ASP.NET自定义错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET Web应用程序中,我在web.config文件中定义了自定义错误页面,如下所示:

In my ASP.NET web application, I have defined custom error pages in my web.config file as follows:

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

如果出现404错误,我的网站将重定向到默认值。 html 页面,但它会将 aspxerrorpath作为查询字符串参数传递给自定义错误页面,如下所示:

In the case of a 404 error, my site redirects to the default.html page, but it passes "aspxerrorpath" as a query string parameter to the custom error page as follows:

http://www.example.com/default.html?aspxerrorpath=/somepathcausederror/badpage.aspx

我不希望这种行为。我希望重定向URL只需阅读:

I don't want that behavior. I want the redirect URL to simply read:

http://www.example.com/default.html

有没有办法实现这一目标?

Is there a way to achieve this?

推荐答案

我的第一个想法是创建一个HttpHandler来捕获 aspxerrorpath ,然后将其剥离。您可能也可以对IIS7中的重写模块执行相同的操作。

My first thought would be to create a HttpHandler which catches url's with aspxerrorpath in it, and strips it. You could probably do the same with the rewrite module in IIS7 as well.

这篇关于如何防止“ aspxerrorpath”作为查询字符串传递到ASP.NET自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆