IIS覆盖ASP.NET中的自定义404错误页面(IIS overriding custom 404 error page in ASP.NET)

编程入门 行业动态 更新时间:2024-10-11 23:20:49
IIS覆盖ASP.NET中的自定义404错误页面(IIS overriding custom 404 error page in ASP.NET)

我正在尝试创建一个404错误页面,目前我已经拥有以下所有内容/尝试了以下所有内容来尝试完成此操作。 当用户键入时:

HTTP://name/something.aspx

它就像它应该的那样工作。 但是如果用户键入:

HTTP://名称/ NotAFile

没有.aspx然后IIS7自己动手,我得到了IIS7附带的可爱错误页面。 目标是网站仅重定向404状态代码(因此不是200或302重定向)。 我在web配置中尝试过:

<customErrors mode="On" defaultRedirect="~/error/Default.aspx redirectMode="ResponseRewrite"> <error statusCode="404" redirect="~/error/NotFound.aspx" /> </customErrors>

这适用于具有.aspx文件扩展名的URL,但不适用于没有扩展名的URL。 与global.asax中的此方法相同

void Application_Error(object sender, EventArgs e) { var serverError = Server.GetLastError() as HttpException; if (serverError != null) { if (serverError.GetHttpCode() == 404) { Server.ClearError(); Server.Transfer("~/error/NotFound.aspx"); } Server.Transfer("~/error/Default.aspx"); } }

对此有相同的结果:(我最后的尝试是将此应用到Web配置:

<system.webServer> <httpErrors existingResponse="PassThrough" /> </system.webServer>

有了这个我只是得到一个没有任何东西的纯白色屏幕......任何想法或评论将不胜感激! 提前致谢!

I am trying to create a 404 error page and currently I have all of the following/tried all of the following to try and accomplish this. When the user types in :

http://name/something.aspx

It works just as its supposed to. But if the user types in:

http://name/NotAFile

with no .aspx then IIS7 takes matters into its own hands and I get the lovely error page that IIS7 comes with. The goal is that the site redirects with only a 404 status code (so not a 200, or a 302 redirect). I have tried in both the web config with:

<customErrors mode="On" defaultRedirect="~/error/Default.aspx redirectMode="ResponseRewrite"> <error statusCode="404" redirect="~/error/NotFound.aspx" /> </customErrors>

This works for the url with a .aspx file extension but not for no extension. Same with this approach in the global.asax

void Application_Error(object sender, EventArgs e) { var serverError = Server.GetLastError() as HttpException; if (serverError != null) { if (serverError.GetHttpCode() == 404) { Server.ClearError(); Server.Transfer("~/error/NotFound.aspx"); } Server.Transfer("~/error/Default.aspx"); } }

The same results are present for this :( My final attempt was to apply this to the web config:

<system.webServer> <httpErrors existingResponse="PassThrough" /> </system.webServer>

With this I just get a plain white screen with nothing on it... Any thoughts or comments would be greatly appreciated!! Thanks in advance!

最满意答案

您的应用程序似乎在经典管道模式下运行。 将其更改为集成,您的问题将得到解决。 这是一篇关于管道模式及其差异的文章 - http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

It seems that your application is running in classic pipeline mode. Change it to integrated and your problem will be fixed. Here is an article about pipeline modes and their differences - http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

更多推荐

aspx,error,尝试,电脑培训,计算机培训,IT培训"/> <meta name="description&quo

本文发布于:2023-08-08 00:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   错误   页面   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!