ASP.Net 自定义会话状态管理

发布于 2024-10-20 07:55:24 字数 50 浏览 3 评论 0 原文

是否可以构建完全自定义的会话状态模式而不是使用 Inproc 或 SQLServer?

Is it possible to build a fully customized Session State Mode instead of using Inproc or SQLServer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倦话 2024-10-27 07:55:24

是的,绝对可以,您可以通过实现 自定义会话状态存储提供程序 http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatestoreproviderbase.aspx">SessionStateStoreProviderBase 类,然后在 web.config 中将会话状态模式设置为此自定义实现:

<sessionState 
    mode="Custom"
    customProvider="SomeCustomProviderName">
    <providers>
        <add name="SomeCustomProviderName"
             type="YourNamespace.CustomSessionStateStore"
             connectionStringName="SomeConnectionString" />
    </providers>
</sessionState>

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:

<sessionState 
    mode="Custom"
    customProvider="SomeCustomProviderName">
    <providers>
        <add name="SomeCustomProviderName"
             type="YourNamespace.CustomSessionStateStore"
             connectionStringName="SomeConnectionString" />
    </providers>
</sessionState>
农村范ル 2024-10-27 07:55:24

这是一个较旧的问题,与我在 2014 年 10 月此时此地所做的事情有关。

基本上,原始答案仍然是正确的,因为您可以构建自己的自定义 OutProc 会话状态管理系统,但 Microsoft 现在更加强大参与开源,您可以轻松访问 MSOpenTech 并下载适用于 Windows 的 Redis 端口 Windows Azure 也支持该功能。

Redis 是一个 OutProc 会话状态管理系统,可以在独立进程/控制台窗口中运行,也可以作为底板会话/键值存储的 Windows 服务运行。

MSOpenTech:

Redis 是一个非常流行的开源、网络化、内存中、键值对
数据存储。它以高性能、灵活性、丰富的设置而闻名
数据结构和简单直接的 API。微软开放技术有
一直在与 Redis 社区合作构建一个生产就绪的
Redis 的 Windows 端口,包括 64 位支持、安装程序
Windows Azure、NuGet 支持等等。

Redis.io简介:

Redis 是一个开源、BSD 许可的高级键值缓存和
店铺。它通常被称为数据结构服务器,因为键
可以包含字符串、散列、列表、集合、排序集合、位图和
超级日志

您可以使用它来存储 ASP.NET MVC、WebAPi 和 SignalR 的会话状态,这在网络场环境中非常方便。

安装包 Microsoft.Web.RedisSessionStateProvider

它可以通过 web.config 轻松配置,当我说简单时,我的意思是简单。

<system.web>
  <sessionState mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" port="6379" accessKey="" ssl="false" />
      </providers>
    </sessionState>
</system.web>

事实上很简单,我一开始以为我一定做错了。 ;)
但这就是将会话状态外包给 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 is a very popular open-source, networked, in-memory, key-value
data store. It is known for high performance, flexibility, a rich set
of data structures, and a simple straightforward API. MS Open Tech has
been working with the Redis community to build a production-ready
Windows port of Redis, including 64-bit support, an installer for
Windows Azure, NuGet support, and much more.

Redis.io Intro:

Redis is an open source, BSD licensed, advanced key-value cache and
store. It is often referred to as a data structure server since keys
can contain strings, hashes, lists, sets, sorted sets, bitmaps and
hyperloglogs

You can use it to store session state for ASP.NET MVC, WebAPi and SignalR which is super handy in a web farm environment.

Install-Package Microsoft.Web.RedisSessionStateProvider

It's easily configured via web.config and when I say easy, I mean easy.

<system.web>
  <sessionState mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" port="6379" accessKey="" ssl="false" />
      </providers>
    </sessionState>
</system.web>

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

忘羡 2024-10-27 07:55:24

我认为可以按照您喜欢的方式进行操作,但是一般使用数据库进行会话状态管理(虽然有一些缺点)可以有很多好处,请查看我的博客以获取简单的从头开始实现
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/

月下凄凉 2024-10-27 07:55:24

我认为对于想要在数据库中实现自定义会话的人来说这是一个有价值的链接: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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文