ASP.NET 从 AD 获取有关用户的数据

发布于 2024-11-26 15:22:43 字数 266 浏览 1 评论 0原文

需要识别内网站点上的用户,windows用户名就是目标。它将被附加到最终发送到 SQL Server 的参数中。

我可以获得 HttpContext.Current.Request.ServerVariables("LOCAL_ADDR") 192.168.112.81

我们这里有一个混合地址包,其中 33% 是固定的,其余的是分配的。

是否有办法识别 AD 中分配给 IP 的用户?如果是这样,您有链接或示例吗?

TIA。

Need to identify user on intranet site, windows user name is the goal. That will be appended to params going to SQL Server in the end.

I can get HttpContext.Current.Request.ServerVariables("LOCAL_ADDR") 192.168.112.81

We have a mixed bag of addresses here, in that 33% are fixed and the rest are allocated.

Is there a recourse to identify the user assigned to an IP within AD? If so do you have a link or an example?

TIA.

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

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

发布评论

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

评论(2

聊慰 2024-12-03 15:22:43

在页面内,可以通过以下方式找到用户名:

Page.User.Identity.Name

HttpContext.Current.User.Identity.Name

在服务调用中

ServiceSecurityContext.Current.WindowsIdentity.Name

它将以域为前缀。

Within a page, the username can be found with:

Page.User.Identity.Name

or

HttpContext.Current.User.Identity.Name

or in a service call

ServiceSecurityContext.Current.WindowsIdentity.Name

It will be prefixed by the domain.

独夜无伴 2024-12-03 15:22:43

IP 不是分配给用户的,而是分配给机器的。不止一个用户可以使用一台机器,所以你的方法没有意义。

而是在您的网站上配置Windows 身份验证,然后您可以使用User MVC 控制器中的属性或 <一个href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.user.aspx" rel="nofollow">User Web 表单页面中的属性。这两个属性都会返回一个 IPrincipal依次具有 Identity 属性,哪个是一个 IIdentity 实例。身份的 name 属性将为您提供用户的帐户名。

IPs are not assigned to users, they are assigned to machines. More than one user can use a machine, so your approach makes no sense.

Instead configure Windows Authentication on your site and then you can use the User property within an MVC controller or the User property in a webforms page. Both these properties return an IPrincipal which in turn has an Identity property, which is an IIdentity instance. The name property of the identity will give you the user's account name.

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