简体   繁体   中英

ASP.Net Httpcontext.Current.User shows last user who spawned thread

Very strange issue I'm facing with ASP.Net and Current User.

Using ASP.Net 4.0.

For some reason, HttpContext.Current.User.Identity.Name reports the User Identity as the last person who hit the server. In other words, it somehow and for some reason caches the Identity.

Heres the scenario: Log in on computer 1 with my own username and it shows fine. Log in on computer 2 with other username and it shows fine.

Refresh Browser on Computer 1 and it shows computer 2 credentials!!!

I've tried just about everything! I had a custom role provider which I turned off and tried every possible setting. Currently I have two lines in my web config which should work just fine.

I've checked the following in IIS: Anonymous is disabled Windows is enabled Disabled Session State!

To test the username, I'm doing this :

lblUserName.Text = HttpContext.Current.User.Identity.Name;

Any Idea what I'm doing wrong? Could this be because i'm using NTLM and not Kerberos?

Any help would be much appreciated

Holy Smokes, what a stupid issue! I found the answer by ripping apart the web.config.

Turns out caching was the issue. I had the following as enabled in my web.config :

 <caching enabled="false"> <profiles> <add duration="72:00:00" location="Client" extension=".aspx" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> <add duration="72:00:00" location="Client" extension=".axd" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> <add duration="72:00:00" location="Client" extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> <add duration="72:00:00" location="Client" extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> <add duration="72:00:00" location="Client" extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> <add duration="72:00:00" location="Client" extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> <add duration="72:00:00" location="Client" extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> </profiles> </caching> 

Disabling caching fixed it! What a strange issue.

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