ASP.NET MVC - 跨子域身份验证/成员身份

Cha*_*eus 10 c# authentication subdomain asp.net-mvc asp.net-membership

在实现基于子域的语言切换器时遇到障碍(en.domain.com加载英语,jp.domain.com加载日语).

如何让单个成员资格系统跨多个子域工作(ASP.NET MVC C#)?

看到一些有关添加domain="domain.com"<forms >web.config中的条目.这样做了,但是在本地visual studio开发Web服务器上进行测试时是否可行?

Jam*_*s S 7

尝试自己创建cookie.

AccountController中你会发现:

FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
Run Code Online (Sandbox Code Playgroud)

"创建并添加到cookie集合".它不允许修改域(但奇怪地允许修改路径).而是在不添加到集合的情况下创建cookie,修改必要的属性,然后添加到集合:

var a = FormsAuthentication.GetAuthCookie(userName, createPersistentCookie);
//if you're debugging right here, a.Domain should be en.example.com; change it
a.Domain = "example.com";
HttpContext.Current.Response.Cookies.Add(a);
Run Code Online (Sandbox Code Playgroud)

詹姆士