如何获取本地网络内访问 ASP.NET Intranet 页面的用户的用户名?

发布于 2024-07-17 20:22:13 字数 118 浏览 5 评论 0原文

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

We have an ASP.NET intranet site, available to users who are either physically at and logged into a local machine or else to users who connect remotely via VPN. Is there a way to automatically get the username of whoever is accessing the page based on the name used to either log into the local machine or that used for the VPN?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

避讳 2024-07-24 20:22:13

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

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

在这里阅读更多相关信息:

在 Intranet ASP.NET Web 应用程序中启用 Windows 身份验证

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

This is possible if you're using Windows Authentication in your pages.

You can use either Page.User.Identity.Name or the more complete System.Web.HttpContext.Current.User.Identity.Name.

Read more about it here:

Enabling Windows Authentication within an Intranet ASP.NET Web Application

If you are, however, using Forms Authentication, you'll have to keep track of the current user yourself, the most common method of which will be by storing their login name in a Session variable.

情深如许 2024-07-24 20:22:13

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

User.Identity.Name

If the authentication is setup to do Integrated Windows authentication then you should be able to get it by accessing

User.Identity.Name

划一舟意中人 2024-07-24 20:22:13

获取用户信息如下:

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?

Get the User information as follows:

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?
笑看君怀她人 2024-07-24 20:22:13

如果身份验证是 Windows,这应该有帮助:

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

If the authentication is windows, this should help:

IIdentity WinId= HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
你另情深 2024-07-24 20:22:13

您可以使用

Page.User.Identity.Name

You can use

Page.User.Identity.Name
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文