在Asp.Net MVC网站维护状态 [英] Maintaining state in Asp.Net MVC website

查看:333
本文介绍了在Asp.Net MVC网站维护状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计基于MVC一个新的网站,我不知道什么是管理国家的正确途径。结果
国家应该包含用户ID和用户信息的一些结构,而他在登录的用户应该在整个会议期间保持(在HTTP请求)

I'm currently designing a new website built on MVC and I wonder what is the right way to manage state.
The state should contain the userId and some structs of the user info, and should be kept during the whole session of the user while he's logged in (across http requests)

重要的标准:搜索
1)支持的可扩展性结果
2)性能

The important criteria:
1) Support scalability
2) Performance

简单的方法是使用会话对象,但它不支持可扩展性。如果在会议期间不同的请求都通过不同的IIS服务器,会话将不会被保留。虽然我听说过负载均衡工具,借道在同一台机器单个会话的所有请求,我不知道它是依靠它一个很好的做法(是不是?)

The easy way is to use the Session object, but it doesn't support scalability. If different requests during the session go through different IIS servers, the session won't be kept. Although I've heard of load balancing tools which route all requests of a single session through the same machine, I'm not sure that it's a good practice to rely on it (isn't it?)

这是我读过有关,是保持状态数据的特殊状态,其中的服务器正在运行RAM DB(如卡桑德拉为Linux或Redis的适用于Windows)另一种选择。但在我看来矫枉过正在这个阶段的发展。

Another option that I've read about, is keeping the state data in special state servers which are running a RAM DB (like Cassandra for Linux or Redis for Windows). But it seems to me an overkill at this stage of the development.

你有什么其他的建议?
我愿与目前一些简单的启动,但保持设计准备在未来更先进的解决方案。

Do you have any other suggestions? I would like to start with something simple at the moment, but keep the design ready for a more advanced solution at the future.

任何的最佳做法或code /设计建议将AP preciated。

Any best practice or code/design suggestions will be appreciated.

谢谢,结果
艾迪。

Thanks,
Edi.

推荐答案

(1)使用的 SQL Server 来存储会话状态

(1) Use Sql Server to Store Session State

(2)使用的Memcached作为一个会话状态提供商

(3)使用一个外部缓存缓存提供商库克自己的解决方案:考虑使用类似的的 ServiceStack缓存框架。利用这一点,你可以使用Redis的,Memcached的,天青或AWS来处理缓存。

(3) Cook up your own solution using Caching on an external caching provider: look into using something like the ServiceStack Caching Framework. Using this, you can use Redis, Memcached, Azure or AWS to handle caching.

接下来,创建的KeyFactory处理生成密钥的具体项目。该项目键将包括用户ID(你总是会从 FormsAuthentication 有用户ID(假设你正在使用 FormsAuthentication )然后存储任何会话数据在缓存中的用户。使用这种方法使用的是缓存在会话,而缓存可以跨多台服务器共享。

Next, create a KeyFactory to handle generation of keys for specific items. The item keys would include the UserId (which you would always have from FormsAuthentication UserId (assuming that you are using FormsAuthentication). Then store any Session data for the user in the cache. Using this approach you are using Caching in place of Session, and the cache can be shared across multiple servers.

请注意:你可以有关于清理出用户的数据时,他们开始一个新的会话不同的做法。可能的方法包括:

Note: you can have different approaches regarding clearing out the user's data whenever they begin a new session. Potential approaches include:


  • 包括在cacheKey用户会话的开始日期时间,当他们不再自动失效条目新鲜

  • 清除出用户所有潜在的条目时,他们开始一个新的会话

这篇关于在Asp.Net MVC网站维护状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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