你怎样才能保持跨多个子域的会话在C#中的MVC? [英] How can you keep a session across multiple subdomains in c# mvc?

查看:86
本文介绍了你怎样才能保持跨多个子域的会话在C#中的MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的购物车程序跳转域名,当它从正常的页面进入提交 - 您 - 详细信息页面。

A shopping cart application I'm working on jumps domain when it goes from the normal page into the submit-your-details page.

长话短说有部署的应用程序的两个副本:为主网站的一台服务器,并与HTTPS为客户详细信息运行的EV证书一台服务器(包括支付,这是一个PCI合规性问题)

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).

我的问题是这样的:

当从 HTTP跳跃://shop.domain - >的 HTTPS://secure.domain (和背部,如果用户浏览回),哪能preserve会议

When jumping from http://shop.domain -> https://secure.domain (and back, if the user browses back), how can I preserve the session?

其琐碎通过使用JSONP饼干跨域,但我不知道在远程方重新连接的会议上与他们无关。

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.

这是一个MVC3 C#的Web应用程序。

This is a for an MVC3 c# web app.

推荐答案

会话的问题是,他们被关在同一个域中。

Problem with Session's is that they are kept in the same domain.

如果您在子域2应用程序您可以随时追加给你的的web.config

If you have the 2 applications in sub domains you can always append this to your web.config

<httpCookies domain=".domain.com"/>

和会做的伎俩,但如果域是完全不同的,最好的办法就是经常推出自己的会话提供者或使用现有的,像SQL。

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.

您可以使用此任何缓存系统,其中,而不是变量追加到一个会话变量,你追加它们到缓存为键/值对,你可以随时使用NoSQL的替代方案(大量的免费帐户的在那里,所以你可以原型,并以推出最后位)做一个概念证明。

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的服务器始终是一个很好的选择和 Couchbase 作为的提供免费的社区版本

Memcached server is always a good alternative and Couchbase as the community version available for free.

这里的窍门是要做到这一点:

The trick here is to do this:

Cache.AddObject(key + "UserInfo-name", "Bruno Alexandre");

其中,可以在后的Global.asax 追加查询字符串值在session_start

where key could be a query string value appended in global.asax upon session_start

而不是这种

Session["UserInfo-name"] = "Bruno Alexandre";

这篇关于你怎样才能保持跨多个子域的会话在C#中的MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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