這可能是重複問題,但我沒有從其他帖子中找到任何解決方案。HttpContext.Current.User.Identity.Name每次都是空的
我正在使用Windows身份驗證,當我在本地系統上構建應用程序時,它的工作正常,但是當我在IIS上部署應用程序時,HttpContext.Current.User.Identity.Name返回null。我已禁用身份驗證設置以外的Windows身份驗證。
var strUserName = HttpContext.Current.User.Identity.Name == "" ? System.Security.Principal.WindowsIdentity.GetCurrent().Name : HttpContext.Current.User.Identity.Name;
我得到strUserName爲空。
<authentication mode="Windows">
</authentication>
<identity impersonate="true"/>
我試圖劃分線和編寫代碼來檢查究竟是什麼returing ...
HttpContext.Current.User.Identity.Name is returning null
System.Security.Principal.WindowsIdentity.GetCurrent().Name is returning NT AUTHORITY\IUSR when impersonate is true
System.Security.Principal.WindowsIdentity.GetCurrent().Name is returning IIS APPPOOL\ApplicationPoolName when impersonate is false
以下幾個環節我已經檢查
User.Identity.Name with windows authentication
我想向您推薦[編輯]您的問題,並添加您發現的其他類似問題,並儘量避免將您的問題標記爲重複。 – kayess
我相信第二個''標籤會覆蓋上面例子中的第一個,所以'mode = Windows'不會被拾取。你可以嘗試合併兩個配置項目嗎? –
您是指服務/ WCF? –