简体   繁体   English

缓存包含子域的不同数据

[英]Cache contains different data for subdomains

I'd like to ask about strange behavior of Cache object. 我想问一下Cache对象的奇怪行为。 I use Cache to store data specific for user (more accurately for session) with SessionID as a key. 我使用Cache来存储特定于用户的数据(对于会话来说更准确),并将SessionID作为键。

For some reason the data in Cache appears not to be the same for different subdomains. 由于某些原因,不同子域的缓存中的数据似乎不同。 I managed to keep SessionID equal across all subdomains: - I set domain attribute in httpCookies element in web config like ".domain.com". 我设法在所有子域中使SessionID保持相等:-我在网络配置(例如“ .domain.com”)的httpCookies元素中设置了域属性。 - I used this trick to ensure that SessionID cookie is stored across all subdomains. -我使用技巧来确保SessionID cookie存储在所有子域中。 - I set sessionState mode to SQLServer. -我将sessionState模式设置为SQLServer。

I ensured that SessionID is really the same for all subdomains. 我确保所有子域的SessionID都相同。 What's more, it is interesting that when I use session state in place of cache, everything works just fine. 而且,有趣的是,当我使用会话状态代替缓存时,一切正常。 Session returns expected data for all subdomains. 会话返回所有子域的预期数据。 But when I use cache with SessionID as a key, cache returns different data for different subdomain. 但是,当我将缓存与SessionID用作键时,缓存会为不同的子域返回不同的数据。

Of course, I could keep it in session state but I'm not really fan of it and try to avoid it whenever I can. 当然,我可以将其保持在会话状态,但是我并不真正喜欢它,并尽可能地避免使用它。

Any ideas would be appreciated. 任何想法,将不胜感激。

What's more, it is interesting that when I use session state in place of cache, everything works just fine. 而且,有趣的是,当我使用会话状态代替缓存时,一切正常。

It works because you store SessionState in centralized location which is SQLServer. 之所以有效,是因为您将SessionState存储在SQLServer的集中位置。

The Cache for the current application domain. 当前应用程序域的缓存。 .

If you want to have same cache for all app domains, you need distributed caching such as Windows Server AppFabric 如果您希望所有应用程序域具有相同的缓存,则需要分布式缓存,例如Windows Server AppFabric

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM