【发布时间】:2010-10-20 03:33:09
【问题描述】:
我们有一个 ASP.NET Intranet 站点,可供实际使用并登录到本地计算机的用户或通过 VPN 远程连接的用户使用。有没有办法根据用于登录本地计算机或用于 VPN 的名称自动获取访问该页面的用户的用户名?
【问题讨论】:
标签: asp.net authentication intranet userid
我们有一个 ASP.NET Intranet 站点,可供实际使用并登录到本地计算机的用户或通过 VPN 远程连接的用户使用。有没有办法根据用于登录本地计算机或用于 VPN 的名称自动获取访问该页面的用户的用户名?
【问题讨论】:
标签: asp.net authentication intranet userid
获取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?
【讨论】:
如果您在页面中使用 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 也将包含表单身份验证用户名。
你可以使用
Page.User.Identity.Name
【讨论】:
如果身份验证是 windows,这应该会有所帮助:
IIdentity WinId= HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
【讨论】:
如果身份验证设置为集成 Windows 身份验证,那么您应该能够通过访问来获取它
User.Identity.Name
【讨论】: