-2

有人遇到过这个楼盘吗?我实际上正在尝试为不同域中的 2 个 asp.net 网站实现单点登录。正在为此寻找示例代码?非常感谢!

4

1 回答 1

1

如果您使用跨域,请查看此页面,您需要确保您也使用无 cookie 身份验证,因为 cookie 不会是跨域的。

这里有另一个 Stack Question的作者提供的不错的代码示例。

if (FormsAuthentication.EnableCrossAppRedirects)
{
text = context.Request.QueryString[name];
if (text != null && text.Length > 1)
{
    if (!cookielessTicket && FormsAuthentication.CookieMode == HttpCookieMode.AutoDetect)
    {
        cookielessTicket = CookielessHelperClass.UseCookieless(context, true, FormsAuthentication.CookieMode);
    }
    try
    {
        formsAuthenticationTicket = FormsAuthentication.Decrypt(text);
    }
    catch
    {
        flag2 = true;
    }
    if (formsAuthenticationTicket == null)
    {
        flag2 = true;
    }
}
if (formsAuthenticationTicket == null || formsAuthenticationTicket.Expired)
{
    text = context.Request.Form[name];
    if (text != null && text.Length > 1)
    {
        if (!cookielessTicket && FormsAuthentication.CookieMode == HttpCookieMode.AutoDetect)
        {
            cookielessTicket = CookielessHelperClass.UseCookieless(context, true, FormsAuthentication.CookieMode);
        }
        try
        {
            formsAuthenticationTicket = FormsAuthentication.Decrypt(text);
        }
        catch
        {
            flag2 = true;
        }
        if (formsAuthenticationTicket == null)
        {
            flag2 = true;
        }
    }
}
}
于 2012-07-22T10:32:00.590 回答