Asp.net

HttpContext.Current.User 為 null,即使 Windows 身份驗證已打開

  • November 2, 2009

在 Windows Server 2008 下的 IIS7 中,我有一個關閉匿名訪問並打開 Windows 身份驗證的虛擬目錄。在我的 web.config 中,我有:

<authentication mode="Windows"/>
<authorization>
           <allow roles="MYGROUP"/>
           <deny users="*"/>
</authorization>

<system.webServer>
   <!-- IIS7 security settings -->
   <security>
       <authorization>
               <add accessType="Deny" users="*"/>
               <add accessType="Allow" roles="MYGROUP"/>
       </authorization>
   </security>
</system.webServer>

然而,當我從 IE 訪問 default.aspx 並在 Global.asax.vb Application_AuthenticateRequest() 中設置斷點時,我得到一個空的 HttpContext.Current.User ,我期待自己的身份。幾乎就像匿名訪問一樣?

我能做些什麼來解決這個問題?一切似乎都在 IIS6 中工作。

將應用程序池移回經典的答案只是延遲問題。

而是不理會應用程序池,並將您的身份驗證檢查從Application_AuthenticateRequest(), 移動到管道中的下一個函式:

Application_AuthorizeRequest(object sender, EventArgs e)

屆時集成的應用程序池已經完成了windows認證讓你不能接收null來自HttpContext.Current.User

管道可以在這裡找到(連結由 CarlosAg 提供)。

可以在asp 網站消息生命週期頁面上找到管道的視覺化。在控制器部分檢查兩個綠色框“身份驗證過濾器”和“授權過濾器”。這些是你正在搞亂的領域。

引用自:https://stackoverflow.com/questions/1663535