如何仅在页面级别而不是在所有网站上启用会话?
我正在开发一个网站来扩展社区服务器,我发现社区服务器在 web.config
中禁用了会话。
现在我有一个我创建的网页,并且必须在其中使用会话,但我不想编辑 web.config sessionState 值,
我可以仅在页面级别启用会话状态吗?或者还有另一个想法可以做到这一点?
I am developing a website to extend community server, and i found that community server disabled the session in the web.config <sessionState mode="Off" />
.
Now i have a webpage that i created and must use session inside it, but i don't want to edit the web.config sessionState value,
Can i enable session state on just the page level? or there is another idea to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您可以仅为单个页面启用会话状态 - 有可能,但不太可能。
相反,您可以考虑使用 ASP.NET 缓存,它类似,但不会隔离会话之间的数据(您必须自己执行此操作)。或者,您可以考虑在应用程序中的某个位置创建一个静态数据结构来管理每个会话的状态。最后,您可以使对象可序列化并将它们存储在 ViewState 中(如果它们不太大)。 ViewState 可以在单个页面(甚至控件)级别进行配置。
您应该尝试与您的组织选择的状态管理方法保持一致。避免服务器端状态可能是有原因的(可能是出于负载平衡之类的目的)。如果不了解此决定背后的原因,您可能会带来意想不到的问题。
I don't know that you can enable session state just for a single page - possible, but unlikely.
Instead, you could look to use either the ASP.NET Cache, which is similar but does not isolate data between sessions (you'd have to do that yourself). Or, you could look to create a static data structure somewhere in your application that manages per-session state. Lastly, you may be able to just make your objects serializable and store them in ViewState (if they aren't to large). ViewState can be configured at the individual page (or even Control) level.
You should try to be consistent with the approach your organization has chosen regarding state management. There may be a reason that server-side state is being avoided (perhaps for something like load balancing). Without understanding the reasoning behind this decision, you may introduce unexpected problems.