当身份验证发生在子域而不是父域时,是否可以跨子域对用户进行身份验证?
例如:
用户登录到site1.parent.com,然后我们需要将他们发送到reporting.parent.com。
即使登录发生在子域中,我能否向报告站点验证它们?
到目前为止,我所做的所有研究都是让用户先登录到父域,然后每个子域都可以访问身份验证 cookie。
最佳答案
当您对用户进行身份验证时,将身份验证 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));
关于c# - 跨子域的表单例份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/608120/