0

We currently have a .net application which is using impersonation, that is setup in the web.config. The application was using this account to authenticate aganist the db. Users were asked to login and forms authentication was used for that. Recently business asked us to change the application to use windows authentication for users instead.

I setup the application to use windows authentication, impersonatation piece was left alone. Everything seems fine, my question was what is the difference between

System.Environment.UserName and HttpContext.Current.User.Identity

Initially i thought they both would return the same thing, the windows account, but UserName is giving me the impersonated account while Identity the windows account.

But according to this post: another Stackoverflow with similar question they should be the same, but i'm not seeing that. I actually want them to be different, but wanted to confirm what i'm seeing is correct.

Community
  • 1
  • 1
Paritosh
  • 4,243
  • 7
  • 47
  • 80
  • The answer from @kprobst in the post you refer to is the correct answer. Rule of thumb: always use HttpContext.Current.User.Identity for web apps. – KiwiPiet Dec 01 '15 at 21:28
  • @KiwiPiet that's what I thought, but then why is it different when I run my test? When testing UserName is giving me the impersonated account and the Identity is the windows account of the user logged into the system. – Paritosh Dec 02 '15 at 14:34

0 Answers0