同步饼干和在不同的子域的会话(asp.net) [英] sync cookies and sessions in different subdomains (asp.net)

查看:91
本文介绍了同步饼干和在不同的子域的会话(asp.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立的asp.net网站,并有多个子域。例如,
one.cookies.com
two.cookies.com

I am building a site in asp.net and have multiple subdomains. For example, one.cookies.com two.cookies.com

我希望我的用户能够在任何的子域,这两个网站的登录才能登录。另外,我想在会话和Cookie ,以保持同步。到目前为止,我还没有找到一个可靠的方法来做到这一点。

I want my users to be able to login at either subdomain and be logged in for both websites. In addition, I'd like the sessions and cookies to be in sync. So far I haven't found a reliable way to do this.

推荐答案

在创建的cookie可以设置域:

When you create the cookie you can set the domain:

HttpCookie cookie = new HttpCookie("name", "value");
cookie.Domain = "cookies.com";

这将使你的cookie是从cookies.com的所有子访问。

This will allow your cookie to be accessible from all subdomains of cookies.com.

如果您使用的是FormsAuthentication,那么你可以设置web.config中的身份验证cookie中的域:

If you are using FormsAuthentication then you can set the domain for the auth cookie in web.config:

<forms name=".ASPXAUTH"
       loginUrl="login.aspx"
       defaultUrl="default.aspx"
       protection="All"
       timeout="30"
       path="/"
       requireSSL="false"
       domain="cookies.com">
</forms>

记住,对于单点登录到多个子工作的ASP.NET应用程序必须使用相同的在这个$ C $的CProject的文章

Remember that for the single sign-on to work on multiple subdomains your ASP.NET applications must share the same machine keys as explained in this CodeProject article.

不同的子域之间共享会话(不同的工作进程)是比较困难的,因为会被限制到一个应用程序,你将有实现自定义会话同步机制。

Sharing sessions between different subdomains (different worker processes) is more difficult because sessions are constrained to an application and you will have to implement a custom session synchronization mechanism.

这篇关于同步饼干和在不同的子域的会话(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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