我们正在尝试在我们的PC(Windows 7,IIS 7.5)上的两个应用程序之间使用身份验证,并且eveything正常。但问题是当我们尝试发布这些网站(Windows Web服务器2008,IIS 7.0)时,交叉验证不起作用!!
经过长时间的调查,我们发现在第二个网站上的以下代码中发生了错误:
Dim formsCookie As HttpCookie = Request.Cookies(FormsAuthentication.FormsCookieName)
If (formsCookie IsNot Nothing) Then
Else
' always null
我们尝试在后面的代码中检查这样的pathes:
Dim ticket As New FormsAuthenticationTicket(1, smsProfile, DateTime.Now, _
DateTime.Now.AddDays(1), True, AdminSessions.UserObj.Pid, _
FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As New HttpCookie(
FormsAuthentication.FormsCookieName,
hash)
If (ticket.IsPersistent) Then
cookie.Expires = ticket.Expiration
End If
Response.Cookies.Add(cookie)
Response.Redirect(smsPortal)
web.config中的:
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" enableCrossAppRedirects="true" domain="mydomain.com.jo" loginUrl="http://..." protection="All" path="/"/>
</authentication>
请告诉我们本地PC中的IIS和服务器之间有什么区别。
感谢。
答案 0 :(得分:2)
浏览器很可能没有将身份验证cookie从第一个站点发送到第二个站点。检查cookie路径和域。两个站点必须位于同一个域中,并且cookie路径必须设置为公共根目录。
有关详细信息,请参阅此链接: Cookie Domains and Paths
为了帮助进行故障排除,请使用Fiddler或Firebug等实用程序查看请求中发送的Cookie,并验证站点1(用户登录的位置)设置的身份验证Cookie是否也发送到站点2 。
如果站点不在同一台服务器上,还要检查它们是否使用相同的machineKey配置。