我正在开发的购物车应用程序从普通页面进入提交您的详细信息页面时会跳转域。
长话短说,部署了两个应用程序副本:一台服务器用于“主”站点,另一台服务器带有在 https 上运行的 ev 证书,用于提供客户详细信息(包括付款;这是 PCI 合规性问题)。
我的问题是这样的:
从 http://shop.domain -> 跳转时https://secure.domain (如果用户向后浏览,则返回),如何保留会话?
使用 JSONP 跨域传递 cookie 很简单,但我不知道如何在远程端处理它们以“重新连接”到会话。
我已经阅读了有关滚动您自己的自定义会话提供程序等的各种内容,但我还没有找到不仅仅是通用建议的内容;当然没有关于如何使用它重新加入会话的示例。
这是一个 MVC3 C# Web 应用程序。
A shopping cart application I'm working on jumps domain when it goes from the normal page into the submit-your-details page.
Long story short there are two copies of the application deployed: one server for the 'main' site and one server with an ev certificate running on https for the customer details (including payment; this is a PCI compliance issue).
My question is this:
When jumping from http://shop.domain -> https://secure.domain (and back, if the user browses back), how can I preserve the session?
Its trivial to pass cookies cross domain using JSONP, but I have no idea what to do with them on the remote side to 'reconnect' to the session.
I have read various things about rolling your own custom session provider, etc. etc. but I haven't found one that is more than just generic advice; certainly no examples of how this might be used to rejoin a session.
This is a for an MVC3 c# web app.
发布评论
评论(3)
Session
的问题在于它们保存在同一个域中。如果您在子域中有两个应用程序,您可以随时将其附加到您的
web.config
中,这样就可以解决问题,但如果域完全不同,最好一种方法始终是推出您自己的会话提供程序或使用现有的会话提供程序,例如 SQL。
为此,您可以使用任何缓存系统,而不是将变量附加到会话变量中,而是将它们作为键/值对附加到缓存中,您始终可以使用NoSQL替代方案(大量的免费帐户,以便您可以进行原型设计并进行概念验证,以便推出最后的部分)。
Memcached 服务器始终是一个不错的选择,Couchbase 作为 社区版本免费提供。
这里的技巧是这样做:
其中
key
可以是附加在session_start
上的global.asax
中的查询字符串值,而不是这个
Problem with
Session
's is that they are kept in the same domain.If you have the 2 applications in sub domains you can always append this to your
web.config
and that will do the trick, but if the domains are completely different, the best way is always to roll out your own session provider or use an existing one, like SQL.
You can use for this any Caching System where instead of append variables into a session variable, you append them into the cache as key/value pair, you can always use a NoSQL alternative (plenty of free accounts out there so you can prototyping and make a proof of concept in order to roll out the final bits).
Memcached server is always a good alternative and Couchbase as the community version available for free.
The trick here is to do this:
where
key
could be a query string value appended inglobal.asax
uponsession_start
instead of this
当你创建cookie时,你必须写
To get that the code is like
,如果有不同的解决方案,那么找到
,然后在machineKey之后写入
When you create cookie then you must write
To get that the code is something like
and if there are different solutions then find
and then write after machineKey
我正在使用函数中的 HttpContext 创建用户会话。
使用此代码,我可以在 3 个子域内共享会话。
I am creating user session using HttpContext from a function.
With this code, I am able to share session within 3 sub-domains.