重定向错误401.2未经授权

时间:2012-06-10 14:22:21

标签: c# asp.net redirect web-config

我一直在尝试重定向错误消息401.2。:未经授权:由于服务器配置导致登录失败,如下所示:

<customErrors defaultRedirect="Error.aspx" mode="On">
      <error statusCode="401" redirect="Unauthorized.aspx" />
    </customErrors>

但它实际上从未实际重定向。它仍然显示默认的Access is denied页面。 我在那里做错了什么?

2 个答案:

答案 0 :(得分:4)

将以下内容添加到global.asax似乎工作正常:

void Application_EndRequest(object sender, EventArgs e)
        {
            if (Response.StatusCode == 401)
                Response.Redirect("Unauthorized.aspx");
        }

答案 1 :(得分:0)

首先尝试一下:

在Unauthorized.aspx.cs上设置Page_Load方法:

private void Page_Load(System.Object sender, System.EventArgs e)
{
    //Put user code to initialize the page here 
    Response.StatusCode = 401;
    Response.TrySkipIisCustomErrors = true;
}

详情请见:

HttpResponse.TrySkipIisCustomErrors Property

IIS 7 Error Pages taking over 500 Errors

第二次尝试: 除了标记之外,还可以使用它来绕过IIS错误页面:

<system.webServer>
      <httpErrors existingResponse="PassThrough" />
</system.webServer>
相关问题