ASP.NET MVC - cross sub domain authentication/membership

前端 未结 3 1561
醉酒成梦
醉酒成梦 2021-02-01 09:41

Hit a roadblock while implementing a sub domain based language switcher (en.domain.com loads English, jp.domain.com loads Japanese).

How do I get a single member

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 10:28

    Try creating the cookie yourself.

    In AccountController you'll find this:

    FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
    

    that "creates and adds to the cookie collection". It doesn't allow modification of the domain (but does allow modification of the path, oddly). Instead create a cookie without adding to the collection, modify the necessary properties, then add to the collection:

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

    James

提交回复
热议问题