![](/img/trans.png)
[英]ASP.Net MVC 5 - Correct way to access HttpContext.Current.User outside of controller?
[英]ASP.Net Httpcontext.Current.User shows last user who spawned thread
我面對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?
任何幫助將非常感激
天哪,這真是個愚蠢的問題! 我通過撕裂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>
禁用緩存修復了! 真是個奇怪的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.