ASP.NET Get data from AD about user

扶醉桌前 提交于 2020-01-05 04:25:09

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6864582/asp-net-get-data-from-ad-about-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!