多租户应用程序中的 ASP.NET 会话和 Cookie
我正在开发一个多租户 ASP.NET MVC 应用程序。
到目前为止,我们一直在使用 HttpContext 来存储请求的一些对象(技术上按租户分区)。
但是,我们需要使用 TempData(使用 Session)并设置身份验证 cookie。
我们的规范:
- 租户可以有多个 url(tenant1.myapp.com 或 mycustomdomain.com)
- 身份验证 cookie 不应由租户共享
- 理想情况下,租户的身份验证 cookie 应由其任何一个 url 共享
会话域是否感知?看来是的。
我可以在身份验证 cookie 上设置多个域吗?
如果有任何其他可能让我困惑的建议,我将不胜感激。实际上,我只需要了解需要为每个租户分区什么(到目前为止,我已经对每个租户的文件系统、数据库和缓存进行了分区)。
谢谢
本
I'm working on a multi-tenant ASP.NET MVC application.
So far we have been using HttpContext to store a few objects for the request (technically partitioned by tenant).
However, we will need to use TempData (uses Session) and set authentication cookies.
Our spec:
- A tenant can have multiple urls (tenant1.myapp.com or mycustomdomain.com)
- Authentication cookies should NOT be shared by tenants
- Ideally, a tenant's authentication cookie should be shared by any one of their urls
Is Session domain aware? It seems to be.
Can I set multiple domains on an authentication cookie?
Advice on anything else that may catch me out would be appreciated. Really I just need to understand what needs to be partitioned for each tenant (up to now I've partitioned the file system, database and cache per tenant).
Thanks
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,会话由 cookie 跟踪,并且由于 cookie 仅限于同一域,因此会话不仅是域感知的,而且是应用程序感知的,这意味着如果您在同一域上有两个应用程序,它们将不会共享会话。
不可以。Cookie 不能在域之间共享。但与会话相反,您可以在同一域上的多个应用程序之间共享它们(通过将 web.xml 中
标记中的domain
属性设置为顶级域)。配置)。这允许在同一域上的应用程序之间实现单点登录。如果您想在不同域的应用程序之间实现单点登录,您将需要不同的方法。By default Session is tracked by cookies and because cookies are restricted to the same domain the session is not only domain aware but also application-aware meaning that if you have two applications on the same domain they won't share session.
No. Cookies cannot be shared between domains. But contrary to sessions you can share them among multiple applications on the same domain (by setting the
domain
attribute to the top level domain in the<forms>
tag in web.config). This is what allows to achieve single sign on between applications on the same domain. If you wanted to achieve single sign on between applications on different domains you will need different approach.您可能需要查看会话分区。
但我不相信您可以开箱即用地跨域共享会话。您可能需要添加自定义会话同步,其中每个域会话通过自定义算法链接到同一用户/租户等。
you may want to look into Session Partitioning.
But I don't believe you can share sessions across domains out of the box. You will likely need to add custom session synchronization, where each domains session is linked by a custom algorithm to the same user/tenant etc.