FormsAuthentication.GetAuthCookie(LoginStr[1].Trim(), false);
这个已经成功了,但User.Identity.Name为什么取不到值?

解决方案 »

  1.   

    不是FormsAuthentication.GetAuthCookie(LoginStr[1].Trim(), false); 
     是FormsAuthentication.SetAuthCookie(LoginStr[1].Trim(), false); 
      

  2.   


    if(HttpContext.User.Identity.IsAuthenticated)
    判断下试试
      

  3.   


    what about your web.config file?it should  like this: <authentication mode="Forms">
    <forms name="shli" loginUrl="~/Login.aspx" protection="All"></forms>
    </authentication>
    <authorization>
    <deny users="?"/>
    </authorization>
      

  4.   

    另外User.Identity.Name是在另外一个页面
      

  5.   

                    FormsAuthentication.SetAuthCookie(LoginStr[1].Trim(), false);
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        Response.Write(HttpContext.Current.User.Identity.Name.ToString());
                    }
    根本不走Response.write,说明SetAuthCookie失败了~
      

  6.   

    <authentication mode="Windows"> 
      

  7.   

    看看在web.config 里面设置了FORM认证没有<authentication mode="Forms">
          <forms name="XXX" path="/" loginUrl="default.aspx" protection="All" timeout="60" defaultUrl="default.aspx">
          </forms>
        </authentication>