2012-06-10 95 views
3

我一直想上的錯誤信息:401.2未經授權重定向:登錄失敗,服務器配置爲按照以下:轉向對錯誤401.2未經授權

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

但它從來沒有真正重定向。它仍然顯示默認的訪問被拒絕頁面。 我在那裏做錯了什麼?

回答

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> 
+0

無更改。 Theres是攔截Global.asax中EndRequest的一種方式,但不知道如何去做。只有我發現的例子在VB –

+0

我已經嘗試了上述兩個步驟。仍然沒有開火,只是去YSOD。它永遠不會到達Unauthorized.aspx頁面,甚至看起來像global.asax –

4

添加下面的Global.asax似乎運作得很好:

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