简体   繁体   English

ASP.Net Httpcontext.Current.User显示生成线程的最后一个用户

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

Very strange issue I'm facing with ASP.Net and Current User. 我面对ASP.Net和当前用户的一个非常奇怪的问题。

Using ASP.Net 4.0. 使用ASP.Net 4.0。

For some reason, HttpContext.Current.User.Identity.Name reports the User Identity as the last person who hit the server. 由于某种原因,HttpContext.Current.User.Identity.Name将用户身份报告为最后一次访问服务器的用户。 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. 这是这种情况:使用我自己的用户名登录计算机1,它显示正常。 Log in on computer 2 with other username and it shows fine. 使用其他用户名登录计算机2,它显示正常。

Refresh Browser on Computer 1 and it shows computer 2 credentials!!! 刷新计算机1上的浏览器,它显示计算机2凭据!!!

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! 我已经在IIS中检查了以下内容:匿名已禁用Windows已启用禁用会话状态!

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? 难道是因为我使用的是NTLM而不是Kerberos?

Any help would be much appreciated 任何帮助将非常感激

Holy Smokes, what a stupid issue! 天哪,这真是个愚蠢的问题! I found the answer by ripping apart the web.config. 我通过撕裂web.config找到了答案。

Turns out caching was the issue. 原来缓存是个问题。 I had the following as enabled in my web.config : 我在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. 真是个奇怪的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.Net MVC 5-在控制器外部访问HttpContext.Current.User的正确方法? - ASP.Net MVC 5 - Correct way to access HttpContext.Current.User outside of controller? 从Thread.CurrentPrincipal设置HttpContext.Current.User - Set HttpContext.Current.User from Thread.CurrentPrincipal 安装.NET Framework 4.5后,HttpContext.Current.User为null - HttpContext.Current.User is null after installing .NET Framework 4.5 HttpContext.Current.User对于无状态会话是否安全? - Is HttpContext.Current.User Safe for Stateless Session? HttpContext.Current.User和HttpContext.User有什么区别 - What is the difference between HttpContext.Current.User and HttpContext.User HttpContext.Current.User 和 this.User.Identity 的区别 - Difference between HttpContext.Current.User and this.User.Identity HttpContext.Current.User未填充启用Windows身份验证 - HttpContext.Current.User not populated with Windows Authentication enabled 角色添加到 HttpContext.current.user 但 isInRole(rolename) 不起作用 - Role added to HttpContext.current.user but isInRole(rolename) is not working 在异步等待中使用 HttpContext.Current.User 的正确方法 - Correct way to use HttpContext.Current.User with async await IsOneWay = true时HttpContext.Current.User为null - HttpContext.Current.User is null when IsOneWay = true
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM