Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IIS覆盖ASP.NET中的自定义404错误页_C#_Asp.net_Iis 7_Http Status Code 404 - Fatal编程技术网

C# IIS覆盖ASP.NET中的自定义404错误页

C# IIS覆盖ASP.NET中的自定义404错误页,c#,asp.net,iis-7,http-status-code-404,C#,Asp.net,Iis 7,Http Status Code 404,我正在尝试创建一个404错误页面,目前我已经完成了以下所有操作/尝试了以下所有操作以尝试并完成此操作。当用户键入时: 它的工作原理和它应该的一样。但如果用户输入: 没有了aspx,IIS7自己处理事情,我得到了IIS7附带的可爱的错误页面。目标是站点只使用404状态代码重定向(因此不是200或302重定向)。我已尝试在两个web配置中使用: <customErrors mode="On" defaultRedirect="~/error/Default.aspx redirectMod

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

它的工作原理和它应该的一样。但如果用户输入:

没有了aspx,IIS7自己处理事情,我得到了IIS7附带的可爱的错误页面。目标是站点只使用404状态代码重定向(因此不是200或302重定向)。我已尝试在两个web配置中使用:

<customErrors mode="On" defaultRedirect="~/error/Default.aspx redirectMode="ResponseRewrite">
     <error statusCode="404" redirect="~/error/NotFound.aspx" />
</customErrors>
同样的结果如下:(我最后的尝试是将其应用于web配置:

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

有了这个,我就得到了一个纯白色的屏幕,上面什么都没有。。。
如果您有任何想法或意见,我们将不胜感激!!提前感谢!

您的应用程序似乎正在经典管道模式下运行。将其更改为集成模式,您的问题将得到解决。下面是一篇关于管道模式及其差异的文章-

对于经典asp,您可以使用此选项

<system.webServer>
    <httpErrors>
      <clear />
      <error statusCode="404" subStatusCode="-1" path="/404.html" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>

以下代码适用于.aspx和其他文件类型:

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");
    }
}
void Application_Error(object sender, EventArgs e)
{
    var serverError = Server.GetLastError() as HttpException;
    if (serverError != null)
    {
        if (serverError.GetHttpCode() == 404)
        {
            Server.ClearError();
            Response.Redirect("~/NotFound.aspx?URL=" + Request.Url.ToString());
        }
        Response.Redirect("~/Default.aspx");
    }
}
Web.config




使用配置中的代码并给出错误页面的完整路径

我在IIS 7.0中也有同样的问题,我使用的是集成模式!@Xaqron将属性runAllManagedModulesForAllRequests=“true”添加到configuration/system.webServer/modules
<system.webServer >
    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1" />
       <error statusCode="404" path="http://www.seair.co.in/Page-not-found.aspx" responseMode="Redirect" />
    </httpErrors>
</system.webServer>