[英]Get user from Windows login in asp.net
I have an internal website and I need to see who is logged onto the Windows PC so that they don't need to type their name themselves. 我有一个内部网站,我需要查看谁登录到Windows PC,以便他们无需自己键入名称。
I have tried: 我努力了:
System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
and 和
string strName = HttpContext.Current.User.Identity.Name.ToString();
It works on my computer but when I use it on the server it doesn't. 它可以在我的计算机上运行,但是当我在服务器上使用时却不能。
This helped me: 这对我有帮助:
<system.web>
<anonymousIdentification enabled="false"/>
</system.web>
I can get user very simple like this: 我可以像这样使用户非常简单:
HttpContext.User
Try using <authentication mode="Windows"/>
尝试使用
<authentication mode="Windows"/>
http://msdn.microsoft.com/en-us/library/ff647076.aspx http://msdn.microsoft.com/en-us/library/ff647076.aspx
Two things you should take care of: 您应该注意两件事:
System.Security.Principal.IPrincipal User = System.Web.HttpContext.Current.User;
System.Security.Principal.IPrincipal User = System.Web.HttpContext.Current.User;
if you needed anything more plz ask 如果您还需要其他任何东西,请询问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.