Need to identify user on intranet site, windo开发者_StackOverflow社区ws 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.
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.
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.
精彩评论