【问题标题】:How to get the username of the user accessing ASP.NET intranet page within local network?如何获取本地网络中访问 ASP.NET 内网页面的用户的用户名?
【发布时间】:2010-10-20 03:33:09
【问题描述】:

我们有一个 ASP.NET Intranet 站点,可供实际使用并登录到本地计算机的用户或通过 VPN 远程连接的用户使用。有没有办法根据用于登录本地计算机或用于 VPN 的名称自动获取访问该页面的用户的用户名?

【问题讨论】:

    标签: asp.net authentication intranet userid


    【解决方案1】:

    获取User信息如下:

    User.Identity.Name \\ Get the User name
    User.Identity.AuthenticationType \\ What is the Authentication type
    User.Identity.IsAuthenticated \\ Is he authenticated?
    User.IsInRole("Administrators") \\ Is he administrator?
    

    【讨论】:

      【解决方案2】:

      如果您在页面中使用 Windows 身份验证,这是可能的。

      您可以使用Page.User.Identity.Name 或更完整的System.Web.HttpContext.Current.User.Identity.Name

      在此处了解更多信息:

      Enabling Windows Authentication within an Intranet ASP.NET Web Application

      但是,如果您使用表单身份验证,则必须自己跟踪当前用户,最常用的方法是将他们的登录名存储在 Session 变量中。

      【讨论】:

      • 请注意,但如果您使用表单身份验证,User.Identity.Name 也将包含表单身份验证用户名。
      【解决方案3】:

      你可以使用

      Page.User.Identity.Name
      

      【讨论】:

        【解决方案4】:

        如果身份验证是 windows,这应该会有所帮助:

        IIdentity WinId= HttpContext.Current.User.Identity;
        WindowsIdentity wi = (WindowsIdentity)WinId;
        

        【讨论】:

        • 您使用的是 Forms 还是 Windows 身份验证?
        • 原来问题是我们的管理员已将匿名访问设置为 true
        • 啊,我明白了。查看匿名访问部分eggheadcafe.com/articles/20050703.asp
        【解决方案5】:

        如果身份验证设置为集成 Windows 身份验证,那么您应该能够通过访问来获取它

        User.Identity.Name

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多