我的项目发布在服务器,想做一个功能,当客户端访问网站时可以获取到这个客户端的Windows登陆用户名,
在网上找了很多方法都不行,如下:
1. System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
           string strName = p.Identity.Name;
2.string strName = HttpContext.Current.User.Identity.Name;
这两种去不到值,Web.config也配置了如下:
<authentication mode="Windows"/>
<identity impersonate="true"/>
3.string userName = Environment.UserName;
4.WindowsIdentity identity = WindowsIdentity.GetCurrent();
  string userName = identity.Name;
  3和4只是获取本地用户(服务器)
5.Page.Request.UserHostAddress;
  Page.Request.UserHostName
这两种只是获取客户端IP地址谁知道怎样获取客户端Windows用户名?

解决方案 »

  1.   

    用Principal没问题。我觉得是要在Web服务器上启用Windows认证才能得到客户端Windows用户名。
      

  2.   

    通常这是不行也是没必要的,别人是通过浏览器去访问的,浏览器可以获取,但是你的程序是在网页里运行的,浏览器的内部信息你是没权利获取的,要不然就是中毒了,杀软会狂叫的
    可以自己写个ActiveX让客户都装上去,如果有必要
      

  3.   

    System.Net.IPAddress ip = System.Net.IPAddress.Parse(Page.Request.UserHostAddress);
    System.Net.IPHostEntry ine = System.Net.Dns.GetHostByAddress(ip);
    Page.Response.Write(ine.HostName);
      

  4.   

    你是localhost吧,呵呵,你这要求能穿透客户端的路由器
      

  5.   

    这是是获取电脑名吧,同Page.Request.UserHostName没什么区别
      

  6.   

    在IIS中配置Windows验证就能获取到客户端用户名了,2和4都可以,但是总是弹出windows验证,怎么能不弹出?
      

  7.   

    http://www.cnblogs.com/fish-li/archive/2012/05/07/2486840.html
    這個不錯