在URL ASP.NET aspxerrorpathASP、URL、aspxerrorpath、NET

2023-09-03 03:17:28 作者:给你的心不要你还

我有一个网站,我用的customErrors在web.config中指定一个自定义错误页,而这工作得很好。自定义404页中的IIS配置(因为如果它不是,我没有得到我的自定义404页)指定。

I have a site where I use CustomErrors in the web.config to specify a custom error page, and that's working just fine. The custom 404 page is also specified in the IIS configuration (because if it's not, I don't get my custom 404 page).

不过,我有一些逻辑,如果一个用户得到一个404,看起来他们的请求的URL,使导航的建议,如果合适的话踢英寸这种逻辑依赖于aspxerrorpath值。在我的开发PC,该aspxerrorpath正确地附加到URL,如下所示: http://localhost:3092/FileNotFound.aspx?aspxerrorpath=/badpage.aspx,但在我的测试网站,有没有aspxerrorpath附加到URL,所以我所有的定制逻辑被旁路,我建议不工作。我不知道这是否是一个IIS配​​置问题,还是其他什么东西。 Web服务器为Windows Server 2008与IIS 7。

But I have some logic that kicks in if a user gets a 404 that looks at their requested URL and make a navigation suggestion, if appropriate. This logic relies on the aspxerrorpath value. On my development PC, the aspxerrorpath is correctly appended to the URL, like so: http://localhost:3092/FileNotFound.aspx?aspxerrorpath=/badpage.aspx, but on my test site, there's no aspxerrorpath appended to the URL, so all of my custom logic is bypassed and my suggestions don't work. I'm not sure if this is an IIS config issue or something else. The web server is Windows Server 2008 with IIS 7.

有什么想法?

非常感谢。

推荐答案

该aspxerrorpath参数传递,如果被抓获.NET错误(在web.config文件中指定的错误页面时)。出现这种情况,如果你使用的是开发Web服务器,或者如果IIS配置为不检查文件是否存在。

The aspxerrorpath parameter is passed if the error was caught by .NET (and the error page specified in web.config is used). This happens if you're using the development web server, or if IIS is configured not to check that the file exists.

如果IIS检查文件是否存在,然后在IIS中配置自定义错误时,并且请求的URL中包括了查询字符串,就像这样

If IIS checks that the file exists, then the custom error configured in IIS is used, and the requested URL is included in the querystring as something like

http://example.com/FileNotFound.aspx?404; http://example.com/badpage的.aspx