对 ASP.NET 站点的更改是否会终止活动会话?
我担心我的用户会话可能被清除。我使用默认的 ASP.NET Session 对象和会话 cookie。我知道会话可能会超时,并且我已将会话的超时值设置为几个小时,以避免意外超时。
但至少还有另外两种情况让我担心。
- 我知道 ASP.NET 会定期回收运行站点/Web 应用程序的应用程序域(不确定我这里的所有术语是否正确)。会话是否在这些回收事件中持续存在?
- 至少在我的开发服务器上,我对站点所做的某些更改(例如,添加新页面)似乎会导致重新编译站点(或其一部分)时活动会话丢失。这似乎并不是每次变化都会发生,但很多变化都会发生。我特别担心这对于我的网站上线时可能发生的更改意味着什么。我想知道我可以更新哪些内容而不导致活动会话被终止的规则。
感谢您的指点。
I'm concerned about the possibility of my users' sessions getting swept away. I am using the default ASP.NET Session object and session cookies. I know that sessions can time out, and I have set the timeout value for my sessions to several hours to avoid surprise timeouts.
But there are at least two other cases I'm worried about.
- I understand that ASP.NET periodically recycles the app domain running a site/web app (not sure if I have all the terminology correct here). Do sessions live across these recycle events?
- At least on my development server, certain changes that I make to the site (e.g., adding a new page) seem to cause the active session to be lost when the site (or part of it) is recompiled. This does not seem to happen with every change, but with many it does. I'm particularly concerned about what this means for the possibility of changes while my site is live. I'd like to know the rules for what I can update without causing active sessions to be killed.
Thanks for any pointers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这取决于您的会话状态模式。您可以在 Microsoft 支持 上找到以下内容的副本:
如果您使用 StateServer 或数据库,当 IIS 检测到网站发生更改时,您的会话数据将不会丢失。
This depends on your mode of session state. Here's a copy of something you can find on Microsoft Support:
If you use StateServer or a database your session data will not be lost when IIS detects a change to the website.
(1) 如果您在回收应用程序池时使用进程中会话模式,您将丢失会话信息
(2) 取决于您是否为 ASP.NET 应用程序使用 Web 应用程序或网站模型。某些文件在应用程序启动时缓存,如果更改则需要重新启动或重新编译。经验法则是,如果更改 Global.asax、\bin 文件夹中添加、删除或编辑文件的配置文件,将重新启动应用程序,并且进程中会话数据将丢失。
ASP.NET Session 有很多缺陷,许多开发人员根本不使用它。我个人更喜欢将数据存储在 SQL Server 的自定义表中(如果可用)。
如果您想提供更多信息,例如您拥有什么版本的 IIS、您是否使用网站或 Web 应用程序模型、您是否有可用的数据库服务器、您是否使用 Web 场或 Web 花园服务器环境以及您想要哪些信息存放多久我可以给你更具体的建议。
(1) If you use In process session mode on Recycling the application pool you'll lose the session information
(2) Depends if you are using web application or web site model for your asp.net application. Some files are cached on application start and require restart or recompilation if they are changed. The rule of thumb is that if you change Global.asax, config file of add, delete or edit file in \bin folder a restart of the application will be issued and In Process Session data will be lost.
ASP.NET Session has many flaws and many developers do not use it at all. I personally prefer to store data in custom tables in the SQL Server (if available).
If you want to provide more information like what version of IIS do you have, do you use web site or web application model, do you have database server available, do you use web farm or web garden server environment, and what information you want to store and for how long I can give you more concrete advice.
如果您使用 InProc 模式,如果 AppPool 回收,您将丢失会话数据,这种情况可能每天左右发生一次(根据默认计划),或者在服务器上大约 20 分钟不活动后发生。
关于页面更新:每当您更改实时站点上的文件时,该站点都有可能重新启动,就像您更改了 web.config 一样。某些文件不会导致完全重新启动,但很难预测哪些文件,而且它还取决于您正在使用的编译模式(批处理或非批处理)。如果您使用默认的按文件夹批量编译模式,则应该能够更改子文件夹中的各个页面,而无需强制重新启动。但是,对母版页、代码或控件的更改可能会导致重新启动,对顶级文件夹的更改也可能导致重新启动(取决于您那里还有其他内容)。
我想我应该补充一点,更改实时站点上的单个文件通常不是一个好主意 - 尽管我确信您有这样做的理由。
If you're using InProc mode, you will lose session data if the AppPool recycles, which can happen either once a day or so (according to the default schedule), or after about 20 minutes of inactivity on the server.
Regarding page updates: any time you change a file on the live site, there's a chance that the site will restart, as if you changed web.config. Certain files won't cause a full restart, but it's not easy to predict which ones, and it also depends on the compile mode that you're using (batch or not). If you're using the default per-folder batch compilation mode, you should be able to change individual pages in subfolders without forcing a restart. Changes to Master pages, code or controls, though, may cause a restart, as can changes to the top-level folder (depending on what else you have there).
I guess I should add that changing individual files on a live site generally isn't a good idea -- although I'm sure you have your reasons for doing so.