private void Page_Load(object sender, System.EventArgs e)
  {
    WindowsPrincipal p = Thread.CurrentPrincipal as WindowsPrincipal;
    Response.Write(p.Identity.Name)
  }
跟web.config还是iis设置有关么?

解决方案 »

  1.   

    are you using authentication or any impersonation?<script language=C# runat='server'>
    private void Page_Load(object sender, System.EventArgs e)
      {
        Response.Write(System.Threading.Thread.CurrentPrincipal.GetType().Name);
       //System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
     
        System.Security.Principal.WindowsIdentity w= System.Security.Principal.WindowsIdentity.GetCurrent();
       if (w != null)
         Response.Write(w.Name);
      }</script>
      

  2.   

    我想获得计算机的域用户名称,但w.Name却显示NT AUTHORITY\SYSTEM,请问我怎样获取呢?
      

  3.   

    if you don't use integrated authentication and impersonation, you will not be able to get that
      

  4.   

    how to use integrated authentication and impersonation?
    我好像见过用DirectoryEntry的,可以实现么?
      

  5.   

    在IIS中去掉当前站点或虚拟目录的匿名认证选项,选中“集成Windows验证”,在web.config中设置<authentication mode="Windows" />
      

  6.   

    A Tale of Three Security Contexts in ASP.NET 
    http://www.devx.com/SummitDays/Article/6666 
      

  7.   

    <authentication mode="Forms">
    <forms loginUrl="login.aspx" />
    using System.Web.Security;
    using System.Configuration;Context.User.Identity.Name
      

  8.   

    最前面两行在Web.config中。一般书中都有的。
      

  9.   

    webdiyer:你的方法是不是只有加入域的用户才能访问网站
      

  10.   

    各位高手,是不是不使用集成Windows验证就没办法获取客户端的域用户名字了?
    另外问一下,集成Windows验证的验证规则是什么?
      

  11.   

    to ahking(aspire):
    应该可以的啊“集成Windows验证的验证规则”怎么理解?有关Windows认证方式,请参看一下这篇文章:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconthewindowsauthenticationprovider.asp
      

  12.   

    to: webdiyer
    我的怎么不可以啊,可否提供一下详细代码?
      

  13.   

    参考:
    http://www.renwen.net/Article_Show.asp?ArticleID=820
    或者这个,有示例代码:
    http://www.dotnetbips.com/displayarticle.aspx?id=10