ASP.NET随机丢失会话值 [英] ASP.NET randomly losing session values

查看:54
本文介绍了ASP.NET随机丢失会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找答案,这一直困扰着我.我们在会话状态(InProc)中存储用户登录信息和有关用户当前活动的其他数据.每隔一段时间,我会收到一个Null Reference异常,试图使用会话变量之一.它发生在带有随机Session变量的随机页面上.我已经修改了web.config httpRuntime和compliation标记以防止appPool重新启动:

I've been searching for answers for quite some time on this as it continues to plague me. We store user login info and other data about the user's current activities in Session State (InProc). Every so often I get a Null Reference exception trying to use one of the session variables. It happens on random pages, with random Session variables. I have modified the web.config httpRuntime and compliation tags to prevent appPool restarts:

<httpRuntime requestValidationMode="2.0" waitChangeNotification="86400" maxWaitChangeNotification="86400" />
<compilation debug="False" strict="false" explicit="true" targetFramework="4.0" numRecompilesBeforeAppRestart="1000" />

我已将IIS设置为在凌晨3点重新启动应用程序池,以确保当人们忙于使用服务器时它不会重新启动.而且我正在记录应用程序池在事件日志中的重启情况,以确保我知道它何时发生.

I have set IIS to restart the app pool at 3am to make sure it doesnt restart when people are busy using the server. And I'm logging app pool restarts in the event log to make sure I know when its happening.

Dim runtime As HttpRuntime = GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic Or BindingFlags.Static Or BindingFlags.GetField, Nothing, Nothing, Nothing)
Dim shutDownMessage As String = runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.GetField, Nothing, runtime, Nothing)

Dim shutDownStack As String = runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.GetField, Nothing, runtime, Nothing)
Dim evtSource As String = "ASP.NET"
Dim log As New EventLog
log.Source = evtSource
log.WriteEntry(String.Format("_shutDownMessage={0}{2}_shutDownStack={1}", shutDownMessage, shutDownStack, vbCrLf & vbCrLf), EventLogEntryType.Warning)

当应用程序池重新启动时,我获得了事件日志条目.发生这些错误时,应用程序池不会重新启动.

I get the event log entries when the app pool restarts. The App Pool is NOT restarting when these errors happen.

当特定的会话变量丢失时,同一用户的其他大多数会话变量仍然存在.此外,通常还会有10-20个用户登录到该站点,这些用户在访问该站点时不会受到影响.
遇到错误的用户将备份,再次浏览相同的页面,它将正常工作.

When particular Session variables are lost, most of the other Session variables for the same user are still in place. Also, there are typically another 10-20 users logged into the site that are unaffected when it happens.
The user that gets the error will back up, go through the same pages again, and it will work fine.

我在运行带有IIS6和.NET 3.5 32bit和4GB内存的Windows Server 2003(32位)上遇到了此问题.大约一年前,作为服务器升级的一部分,我们获得了一个新的Web服务器-Windows Server 2008(64位))以16GB的内存运行IIS 7.我将网站升级到了.NET 4.0 64位.在新机器上仍然存在相同的问题(通常每天1-3次-一天中的随机次数).

I was having this problem on a Windows Server 2003 (32bit) running IIS6 with .NET 3.5 32bit and 4GB of memory.. As part of our server upgrades about a year ago we got a new webserver - Windows Server 2008 (64bit) running IIS 7 with 16GB memory. I upgraded the website to .NET 4.0 64bit. Still having the same problems on the new machine (usually 1-3 times per day - at random times through the day).

由于它的随机性,我无法使其在调试中发生,但我确实相信它在我们的开发环境中也是随机发生的.开发服务器实际上具有与生产服务器相同的规格.
两种环境都是隔离的,并且作为单个Web服务器运行,而不是Web场的一部分.

I cant make it happen in my debugging due to its random nature, but I do believe it happens randomly on our dev environment as well. The dev server has virtually the same specs as the production one.
Both environments are isolated and running as a single web server, not a part of a web farm.

我想我可能会尝试实现一个状态服务器以退出InProc模式,但这只是黑暗中的又一刺..
除了尝试使用状态服务器外,我还能采取其他措施来确定何时发生或防止这种情况发生吗?

I'm thinking that I may try to implement a State Server to get out of the InProc mode, but that's just another stab in the dark..
Other than trying the State Server, is there anything else I can do to identify when this happens or prevent it?

推荐答案

对于感兴趣或正在处理类似问题的任何人,我想在这里跟进我的问题原因.

For anyone that is interested, or dealing with similar issues, I wanted to follow up with the cause of my problem here.

我为应用程序缓存和会话状态实现了 NCache 进程外状态服务器大约7或8个月前.不幸的是,将会话移出进程并没有对我在站点上选择报告期间丢失随机会话变量的问题没有任何影响.而且,由于我一直无法复制此问题,因此直到最近又有另一个问题使我的脑袋熄灭时,我才投入更多的精力来尝试解决此问题.

I implemented NCache out-of-process state server for Application Cache and Session State about 7 or 8 months ago. Unfortunately, moving the session out-of-process has not had any impact of my problem of losing random session variables during report selection on my site. And, as I had been unable to replicate this problem, I had not put more effort into trying to fix it until recently when another problem made the light go off in my head.

要点很明确-我没有在我未意识到的地方覆盖会话变量,但是问题是用户打开了第二个(或第三个)选项卡来并排比较报告选择选项.我们有几个自定义报告,用户可以在其中选择多个选项来生成自定义报告(可以像创建一个自定义报告的向导控件那样想一下).如果用户处于第3步(共5步),然后打开一个新选项卡并再次开始执行报告选择过程,则新选择将覆盖两个选项卡共享同一会话的旧选择.我通过打开多个选项卡并逐步完成选择过程来验证了这种情况.

To get to the point - I was not overwriting the session variables somewhere that I didnt realize, but the problem was the user was opening up a second (or third) tab to compare report selection options side by side. We have several custom reports where the user can select multiple options to generate custom reports (think of it like a wizard control where there are several steps to create a custom report). If a user is on step 3 of 5, and then opens a new tab and starts going through the report selection process again, the new selections are overwriting the old selections b/c the 2 tabs shared the same session. I verified this was the case by opening multiple tabs and stepping through the selection process.

我正在尝试区分多个报告运行,以便使用其他报告选择中的唯一会话密钥存储一个报告的选择.事实也证明这很困难,但与我认为缺少会话数据的问题并没有真正的联系.

I am in the process of trying to distinguish between multiple report runs so that the selections for one report are stored using a unique session key from other report selections. That is proving difficult as well, but is not really related to the problem I thought I was having with missing session data.

如果有人找到此帖子,并认为他们随机丢失了会话数据并且无法复制,请尝试调试您的网站并打开多个选项卡.同时浏览两个标签对我来说是个问题.

If anyone finds this post and thinks they are losing session data randomly and cant replicate it, try debugging your site and opening multiple tabs. Stepping through both tabs at the same time illuminated the problem for me.

HTH

这篇关于ASP.NET随机丢失会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆