从asp.net的Windows登录获取用户

问题描述:

我有一个内部网站,我需要查看谁登录到Windows PC,以便他们不需要自己键入他们的名称。从asp.net的Windows登录获取用户

我曾尝试:

System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; 

string strName = HttpContext.Current.User.Identity.Name.ToString(); 

它工作在我的电脑上,但是当我用它在服务器上没有。

+0

什么身份验证模式是您使用来识别用户? – SeanCocteau 2012-02-22 12:55:26

使用try <authentication mode="Windows"/>

http://msdn.microsoft.com/en-us/library/ff647076.aspx

+0

我已添加 及其stil无法正常工作 – Rene 2012-02-22 11:27:11

+0

请粘贴验证方法获取Principal和IIS设置的代码 – AshokD 2012-02-22 11:36:52

两件事情你应该照顾:

  1. 在web.config:`
  2. 要获取当前用户,使用此: System.Security.Principal.IPrincipal User = System.Web.HttpContext.Current.User;

,如果你需要什么更多的PLZ问

帮我:

<system.web> 
    <anonymousIdentification enabled="false"/> 
</system.web> 

我能得到用户的喜欢这个很简单:

HttpContext.User