【发布时间】:2012-09-03 18:52:18
【问题描述】:
我有 2 个网站,第一个是 myFirst.domain.com,第二个是 mySecondSite.domain.com。
它们位于两个不同的网络服务器上,我的目标是允许跨站点身份验证(我真正需要的是共享 FormsAuthentication Cookie)。
我已经正确设置了我的web.config 文件(机器密钥节点、表单节点)。唯一的区别是 loginUrl 在 myFirstSite 上显示为 ~/login.aspx,而在 mySecondSite 上显示为 http://myFirstSite.com/login.aspx。
请注意,我没有虚拟目录,我只有 2 个不同的网络应用程序。
问题:当我从 mySecondSite 到达 myFirstSite 登录页面时,我从未从登录页面重定向,似乎没有写入 cookie。
以下是关于这个问题的一些sn-ps:
MyFirsSite:
<machineKey validationKey="..." decryptionKey="..." validation="SHA1" decryption="AES" />
<authentication mode="Forms">
<forms loginUrl="login.aspx" name="authCookie" enableCrossAppRedirects="true"></forms>
</authentication>
<authorization>
<deny users="?" />
<allow users="*"/>
</authorization>
MyFirstSite 后面的代码:
FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, "userName..", DateTime.Now, DateTime.Now.AddMinutes(30), true, "roles..");
string ticket = FormsAuthentication.Encrypt(fat);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticket);
authCookie.Expires = fat.Expiration;
authCookie.Domain = "myDomain.com";
Response.Cookies.Add(authCookie);
//Here is other stuff about querystring checking in order to execute exact redirect, however it's not working, I always return to the login page.
MySecondSite:
<machineKey validationKey="..." decryptionKey="..." validation="SHA1" decryption="AES"/>
<authentication mode="Forms">
<forms loginUrl="http://myFirstSite.domain.com/login.aspx?queryStringToIndicateUrlPage" enableCrossAppRedirects="true"></forms>
</authentication>
<authorization>
嗯,就是这样。不幸的是,它不起作用。
请不要关注queryStringToIndicateUrlPage,这只是一个简单的解决方法,以便知道我是否必须在同一个应用程序或另一个应用程序上重定向。
【问题讨论】:
标签: asp.net forms-authentication httpcookie