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

发布于 2024-12-27 19:14:50 字数 564 浏览 3 评论 0原文

我在 ASP.Net 和当前用户方面面临着非常奇怪的问题。

使用 ASP.Net 4.0。

由于某种原因,HttpContext.Current.User.Identity.Name 将用户身份报告为最后访问服务器的人。换句话说,它以某种方式并出于某种原因缓存了身份。

场景如下: 使用我自己的用户名登录计算机 1,显示正常。 用其他用户名登录计算机2,显示正常。

刷新计算机 1 上的浏览​​器,它会显示计算机 2 的凭据!

我已经尝试了几乎一切!我有一个自定义角色提供程序,我将其关闭并尝试了所有可能的设置。目前我的网络配置中有两行应该可以正常工作。

我在 IIS 中检查了以下内容: 匿名已禁用 Windows 已启用 禁用会话状态!

为了测试用户名,我这样做:

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

知道我做错了什么吗? 这可能是因为我使用的是 NTLM 而不是 Kerberos 吗?

任何帮助将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尾戒 2025-01-03 19:14:50

圣烟,多么愚蠢的问题啊!我通过分解 web.config 找到了答案。

事实证明缓存是问题所在。我在 web.config 中启用了以下内容:

<缓存已启用=“false”>
  <个人资料>
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.aspx”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.axd”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.js”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.css”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.png”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.jpg”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
    <添加持续时间=“72:00:00”位置=“客户端”扩展=“.gif”策略=“CacheUntilChange”kernelCachePolicy=“CacheUntilChange”/> />
  

禁用缓存修复了它!
多么奇怪的问题啊。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文