【问题标题】:get user name asp.net windows auth获取用户名 asp.net windows auth
【发布时间】:2011-10-01 12:21:29
【问题描述】:

所以我做了一个简单的 web 表单,在 iis 的 windows auth 中设置。然后我将它部署在我的服务器上并尝试登录。它提示我一个登录框,我输入我的信息,看起来它与活动目录一起工作正常。

如果我输入错误,它将无法工作等等。

显然我需要知道谁是登录用户

Response.Write(HttpContext.Current.User.Identity.Name.ToString());

我在其他帖子中发现了这个,但它对我不起作用......

如何获取登录框中填写的信息?

【问题讨论】:

    标签: asp.net windows-authentication


    【解决方案1】:

    如果您使用asp.net membership 提供程序,您可以获得当前登录的用户

    System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
    
    User.Identity.IsAuthenticated  
    

    可用于判断用户是否登录成功

    【讨论】:

    • Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());返回我 AUTORITE NT\SERVICE RÉSEAU, edit ,这不是我用来登录的用户。我使用了 davetest
    • 使用这个来获取用户名 User.Identity.Name 并且这篇文章得到了关于这个social.msdn.microsoft.com/Forums/en/pex/thread/…的有用信息
    • 这个方法对我有用。设置<identity impersonate="true"> 没有。事实上,将 impersonate 设置为 true 会给我 NT AUTHORITY\IUSR,这是默认的匿名 IIS 用户。
    【解决方案2】:

    <identity impersonate="true" /> 在网络配置中,解决了我的问题。
    http://msdn.microsoft.com/en-us/library/ff647076.aspx 帮助了我。
    谢谢。

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      相关资源
      最近更新 更多