ASP.Net 自定义会话状态管理
是否可以构建完全自定义的会话状态模式而不是使用 Inproc 或 SQLServer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是否可以构建完全自定义的会话状态模式而不是使用 Inproc 或 SQLServer?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
是的,绝对可以,您可以通过实现 自定义会话状态存储提供程序 http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatestoreproviderbase.aspx">SessionStateStoreProviderBase 类,然后在 web.config 中将会话状态模式设置为此自定义实现:
Yes, absolutely, you could write a custom session state store provider by implementing SessionStateStoreProviderBase class and then set the session state mode to this custom implementation in web.config:
这是一个较旧的问题,与我在 2014 年 10 月此时此地所做的事情有关。
基本上,原始答案仍然是正确的,因为您可以构建自己的自定义 OutProc 会话状态管理系统,但 Microsoft 现在更加强大参与开源,您可以轻松访问 MSOpenTech 并下载适用于 Windows 的 Redis 端口 Windows Azure 也支持该功能。
Redis 是一个 OutProc 会话状态管理系统,可以在独立进程/控制台窗口中运行,也可以作为底板会话/键值存储的 Windows 服务运行。
MSOpenTech:
Redis.io简介:
您可以使用它来存储 ASP.NET MVC、WebAPi 和 SignalR 的会话状态,这在网络场环境中非常方便。
它可以通过 web.config 轻松配置,当我说简单时,我的意思是简单。
事实上很简单,我一开始以为我一定做错了。 ;)
但这就是将会话状态外包给 Redis 所需的一切。
它是一个高性能的移植,非常接近原始的 POSIX 版本。
我们将其用于金融服务应用程序,该应用程序通过 Signalr 遇到高负载的实时推送和拉取,如上所述,它还“支持”Redis 来维护集线器会话状态。
因此,虽然您仍然可以按照已接受的答案进行操作,但大约 3 年半后,我会寻找默认 ASP.NET 会话管理体验的一些替代方案,这些方案可通过 OSS 免费提供。
https://github.com/MSOpenTech/redis
http://www.codeproject.com/Articles/636730/Distributed-Caching-using-Redis
This is an older question relating to something I'm doing in the here and now of Oct 2014.
Basically, the original answers are still correct, in that you can build your own custom OutProc session state management system but with Microsoft now being much more involved with open source, you could just as easily trip along to MSOpenTech and download the Redis port for Windows which is also supported by Windows Azure.
Redis is an OutProc session state management system that can be run in a stand alone process/console window or as windows service for backplane session/ key value store.
MSOpenTech:
Redis.io Intro:
You can use it to store session state for ASP.NET MVC, WebAPi and SignalR which is super handy in a web farm environment.
It's easily configured via web.config and when I say easy, I mean easy.
So easy in fact I at first thought I must be doing it wrong. ;)
But that's all it takes to farm out session state to Redis.
Its a port with high performance, very close to the original POSIX version.
We are using it for a financial services app which encounters high loads of realtime pushes and pulls via Signalr, which as above also "supports" Redis for maintaining hub session state.
So while you can still do as the accepted answers, some 3 and a half years later I would look towards some of these alternatives to the default ASP.NET session management experience which are available, for free, via OSS.
https://github.com/MSOpenTech/redis
http://www.codeproject.com/Articles/636730/Distributed-Caching-using-Redis
我认为可以按照您喜欢的方式进行操作,但是一般使用数据库进行会话状态管理(虽然有一些缺点)可以有很多好处,请查看我的博客以获取简单的从头开始实现
http://techblog.alkumait.net/index.html php/2011/12/net-custom-session-implementation/
I think it is possible to do it the way you like, but using Databases in general for session state management (while have some drawbacks) can have a lot of benefits, check my blog for a simple from-scratch implementation
http://techblog.alkumait.net/index.php/2011/12/net-custom-session-implementation/
我认为对于想要在数据库中实现自定义会话的人来说这是一个有价值的链接:http://msdn.microsoft.com/en-us/library/ms178589.aspx
I think this is a valuable link for people who want to have a custom session implementation at the database: http://msdn.microsoft.com/en-us/library/ms178589.aspx