代码之家  ›  专栏  ›  技术社区  ›  sclarson

Page.User.Identity.Name在子域页面上为空

  •  1
  • sclarson  · 技术社区  · 16 年前

    所有表单验证页都设置为使用相同的名称,并且在验证页上,cookie添加了以下代码段:

     FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
     System.Web.HttpCookie MyCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(User.Identity.Name.ToString(), false);
     MyCookie.Domain = ConfigurationManager.AppSettings["domainName"];
     Response.AppendCookie(MyCookie);
    

    当我登录到signon.mysite.com时,page.user.identity.isauthenticated和page.user.identity.name属性都可以正常工作。当我导航到subdomain.mysite.com时,page.user.identity.isauthenticated返回true,但名称为空。

    我试图用下面的方法从cookie中检索它,但它也是空白的。

     HttpCookie cookie = Request.Cookies[".ASPXAUTH"];
     FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(cookie.Value);
     user2_lbl.Text = fat.Name;
    

    当我在谷歌上搜索这个问题时,我发现一些人说必须在global.asax中添加一些内容,而另一些人则说没有必要。

    目标是能够登录到身份验证子域,并从根站点和其他子域访问用户标识。机器密钥在所有web.config中都匹配,并且AppSettings[“domainName”]当前设置为“mysite.com”。

    1 回复  |  直到 16 年前
        1
  •  4
  •   Jerod Venema    16 年前

    将“mysite.com”改为“.mysite.com”(注意前面的“.”)。

    这将告诉浏览器cookie对子域也是有效的。

    推荐文章