0
我做了一個web應用程序,它顯示右上角的Windows用戶名。 如果我打開localhost:5903/index.aspx
上的webapp,我會得到正確的Windows用戶。 這樣的 -
IIS沒有拿起Windows用戶
但是,如果我打開localhost/db/index.aspx
我得到IIS應用程序池的用戶 -
這裏DB是有我的應用程序的目錄。
我不知道爲什麼會發生這種情況。我希望localhost也顯示正確的用戶名。
我的IIS樹,這裏DB(1)是我的webapp -
我的C#代碼,其拾取Windows身份驗證 -
<li><% string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;%>
<a><%= userName %></a>
</li>
Windows身份驗證已經啓用。我禁用匿名。不用找了。仍然得到IIS AppPool –
更新了上面的答案..使用HttpContext.Current.User.Identity.Name; –
它的工作!你能告訴我有什麼區別,爲什麼它不與本地主機一起工作? –