2012-09-21 25 views

回答

2

我以前用過這個,試試它是否適合你

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 
+0

它的運作效果非常好。你必須知道我是否可以在web.config而不是IIS中設置它? – RollRoll

+0

我不確定。 – codingbiz

+0

這在終端服務場景中對我來說很方便。謝謝。 – aboy021

1

您需要:HttpContext.Current.User或從控制器訪問HTTP上下文。

+0

控制器中沒有來自HttpContext的Current, – RollRoll

+0

Current對於HttpContext類本身是靜態的。 – eulerfx

+0

for MVC Controller包含HttpContext,它是System.Web.HttpContextWrapper,它沒有current.user。你的意思是名稱返回空的System.Web.HttpContext.Current.User。 System.Security.Principal.WindowsIdentity.GetCurrent()。名稱正常工作。感謝您的回答,+1,這將有助於闡明希望獲得相同信息的下一個用戶 – RollRoll

相關問題