Reputation: 1225
I am using windows authentication in a ASP.Net Web Application and in the code-behind attempting to retrieve the logged in user name. I am using this routine WindowsIdentity.GetCurrent().Name but instead of getting the name of the user, I am getting - NT AUTHORITY\NETWORK SERVICE. What do I need to change or are my users logging in a different way than expected?
Upvotes: 0
Views: 1604
Reputation: 19305
Add the following to your web.config:
<system.web>
<identity impersonate="true"/>
</system.web>
This will make your web app impersonate the currently logged in user. That does have some implications. An important one is that the logged in user must have the proper rights to files, folders, databases and so on.
If you don't want that, you can use User.Identity
instead of WindowsIdentity.GetCurrent()
.
Upvotes: 1
Reputation: 1374
Use this.Context.User.Identity.Name
, which will get the identity for the current HTTPContext object: http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx
Upvotes: 3