本文介绍了IIS覆盖在ASP.NET自定义404错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个404错误页面,目前我有以下全部/试过所有的以下尝试做到这一点。当用户类型:

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 :

它的工作原理就像它应该。但如果用户类型:

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

没有的.aspx然后IIS7事宜需要到自己手中,我得到可爱的错误页面,IIS7自带的。我们的目标是,该网站只有404状态code(所以不是200或302重定向)重定向。我曾在这两个与web配置尝试:

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>

这适用于具有.aspx文件扩展名的URL,但不是没有扩展名。同样的,在Global.asax这种方法

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");
    }
}

同样的结果是这个present :(我的最后一次尝试是这个适用于web配置:

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>

有了这个,我只是得到一个纯白色的屏幕,没事就它...
任何想法或意见将大大AP preciated!在此先感谢!

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

推荐答案

看来你的应用程序在经典管道模式下运行。将其更改为综合您的问题将得到解决。下面是一些关于管道模式和分歧的一篇文章 -

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/

这篇关于IIS覆盖在ASP.NET自定义404错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:40