代码之家  ›  专栏  ›  技术社区  ›  Miyagi Coder

跨子域的表单身份验证

  •  26
  • Miyagi Coder  · 技术社区  · 17 年前

    用户登录到site1.parent.com,然后我们需要将他们发送到reporting.parent.com。

    即使登录发生在子域中,我也可以向报告站点对其进行身份验证吗?

    到目前为止,我所做的所有研究都是让用户先登录父域,然后每个子域都可以访问身份验证cookie。

    7 回复  |  直到 14 年前
        1
  •  30
  •   jro    17 年前

    当您对用户进行身份验证时,将身份验证cookie的域设置为二级域,即parent.com。每个子域都将根据请求接收父域的cookie,因此可以对每个子域进行身份验证,因为您将有一个共享的身份验证cookie可供使用。

    身份验证码:

    System.Web.HttpCookie authcookie = System.Web.Security.FormsAuthentication.GetAuthCookie(UserName, False);
    authcookie.Domain = "parent.com";
    HttpResponse.AppendCookie(authcookie);
    HttpResponse.Redirect(System.Web.Security.FormsAuthentication.GetRedirectUrl(UserName, 
                                                                           False));
    
        2
  •  10
  •   Jeff Martin    17 年前

        3
  •  7
  •   Tr1stan    16 年前

    顺便说一句,我发现在使用jro的方法+1后,FormsAuthenication效果很好。从www/以外的子域调用SignOut()方法时不起作用。(我猜是因为.Domain属性不匹配)-为了解决这个问题,我使用了:

    if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    HttpCookie myCookie = new HttpCookie(FormsAuthentication.FormsCookieName);
                    myCookie.Domain = "parent.com";
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie);
                }
    
        4
  •  7
  •   Jack0fshad0ws    15 年前

    除了将cookie设置为父域外,还需要确保所有站点(应用程序)具有相同的validationKey和decryptionKey(),以便它们都能识别彼此的身份验证票证和cookie。这篇文章不错 http://www.codeproject.com/KB/aspnet/SingleSignon.aspx

        5
  •  5
  •   Dhanuka777    11 年前

    setting "domain" Here 这是我遇到的签到问题。这里的诀窍是有一个“。因为域的前缀设置为cookie的“.parent.com”(使用cookie检查器)。

    <authentication mode="Forms">          
          <forms cookieless="UseCookies" defaultUrl="~/Default" loginUrl="~/user/signin" domain=".parent.com"  name="FormAuthentication" path="/"/>
        </authentication>
    
        6
  •  4
  •   GEOCHET S.Lott    17 年前

    一个想法是:当你将它们重定向到边界之外时,给它们一个一次性通行令牌,然后告诉接收子域期待它们(这个用户,来自这个IP,使用这个令牌)。

        7
  •  3
  •   iMatoria    13 年前

    要做的两件事:

    1. MachineKey在所有web.config(主域和子域)中应相同

    跟随 following