我知道Request.ServerVariables["LOGON_USER"]可以获取客户端的信息,但是必须在IIS里取消匿名登录,否则就是空字符串。
如果取消匿名登录,输入地址时总会弹出windows的身份验证对话框。
所以此方法行不通请教是否有其他方法能够在asp.net代码中获取客户端的用户信息(登录使用的帐号名,所属的域等)

解决方案 »

  1.   

    WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity;
    WindowsImpersonationContext ctx = null;
    try
    {
        // Start impersonating.
        ctx = winId.Impersonate();
        // Now impersonating.
        // Access resources using the identity of the authenticated user.
    }
    // Prevent exceptions from propagating.
    catch
    {
    }
    finally
    {
        // Revert impersonation.
        if (ctx != null)
            ctx.Undo();
    }
      

  2.   

    刚才那个不对
    WindowsIdentity   winId   =   (WindowsIdentity)HttpContext.Current.User.Identity; 
    WindowsImpersonationContext   ctx   =   null; 
    try 

                    ctx   =   winId.Impersonate(); 
            WindowsIdentity.GetCurrent().Name
            } 
    catch 


    finally 

            //   Revert   impersonation. 
            if   (ctx   !=   null) 
                    ctx.Undo(); 
    }
      

  3.   

    楼上的谢谢,可惜不行。我是B/S结构的,就是说在S端要通过浏览器响应获取客户端的信息
      

  4.   

    一样,不取消匿名登录的话仍然得到空字符串
    使用windows登录会弹出来那个对话框......
      

  5.   

    用vs2005的LoginName控件可以做到
      

  6.   

    LoginName?直接用铁定是空,要是输入了再用。有意义么,我这边需求就是不用登录界面