ASP.NET Get user data from AD

You must identify the user on the intranet site, the goal is the Windows username. This will be added to the parameters going to SQL Server at the end.

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

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

Is it possible to identify the user assigned to IP in AD? If you have a link or an example?

TIA.

+1
source share
2 answers

Inside the page, the username can be found with:

 Page.User.Identity.Name 

or

 HttpContext.Current.User.Identity.Name 

or when calling a service

 ServiceSecurityContext.Current.WindowsIdentity.Name 

It will be the domain prefix.

+2
source

IP addresses are not assigned to users; they are assigned to machines. More than one user can use the machine, so your approach does not make sense.

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

0
source

Source: https://habr.com/ru/post/900488/


All Articles