简体   繁体   中英

HTTPcontext not returning correct result

I am trying to fetch the current user name using HTTPcontext object using

string username=HttpContext.Current.User.Identity.Name

but I am observing weird behavior ie when I load first time I get username as NT AUTHORITY\\IUSR but when I load second or third time I get the correct logged in username. Couldn't figure out why on first run correct username is not getting returned.

This ia actually a feature called ASP.NET Impersonation . which is enabled for your application.

In this instance, ASP.NET impersonates the token passed to it by IIS, which is either an authenticated user or the anonymous Internet user account (IUSR_machinename). That is what exactly happening to your application. you can read about Impersonation and how to control it at MSDN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM