问题
I know I can share forms authentication across 2 subdomains sub1.domain.com
, sub2.domain.com
by using the following Web.config setting:
<authentication mode="Forms">
<forms domain="domain.com" />
</authentication>
However, I have 2 "sub-sub" domains (not sure if there's a better term for that) a.sub.domain.com
, and b.sub.domain.com
. Now I want to share the forms authentication cookies only on sub.domain.com
, and not my entire domain.com
. Is it possible to do this?
I tried the obvious solution below but it doesn't work, and always redirects back to the login page:
<authentication mode="Forms">
<forms domain="sub.domain.com" />
</authentication>
Is it possible to share the cookies only across domains that end with sub.domain.com
?
回答1:
So it turned out that my old cookies in my browser were somehow conflicting with the new setting.
After clearing all domain.com
cookies, the solution I was trying now works, in case anyone faces a similar situation.
Also note I believe it's preferable to prepend a .
to the domain:
<authentication mode="Forms">
<forms domain=".sub.domain.com" />
</authentication>
来源:https://stackoverflow.com/questions/18462755/is-it-possible-to-share-forms-authentication-only-across-sub-sub-domains