1

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SteveO
  • 477
  • 2
  • 9
  • 17
  • What do you mean by "identify the user assigned to an IP within AD"? – hatchet - done with SOverflow Jul 28 '11 at 19:49
  • The IP of a current connection is **not** available in AD - AD is a rather static repository of information - it is **not** a "operations management" system that handles dynamic stuff like users logged in and their IP's and stuff like that. – marc_s Jul 28 '11 at 19:49

2 Answers2

2

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.

Erix
  • 7,059
  • 2
  • 35
  • 61
0

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.

blowdart
  • 55,577
  • 12
  • 114
  • 149