FormsAuthenticationTicket tk = new FormsAuthenticationTicket(
                                        1,                //指定版本号:可随意指定
                                    memberid.ToString(), //登录用户名:对应 Web.config 中 <allow users="Admin" … /> 的 users 属性
                                        System.DateTime.Now,   //发布时间
                                        System.DateTime.Now.AddYears(100),   //失效时间:100 年以后,够永够久了吧
                                    true,
                                    “我的信息” //用户数据:可用 ((System.Web.Security.FormsIdentity)User.Identity).Ticket.UserData 获取
                   );
                //HttpContext.Current.Items["UseInfo"] = null;//reset the infor                string str = FormsAuthentication.Encrypt(tk);//加密身份验票
                
                System.Web.HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, str);
我在login页面里面在userData里面放入我的信息,

        void application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            if (context.Request.IsAuthenticated)
            {
                HttpCookie authCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);//解密 
                string UseInfo = authTicket.UserData;
里面把userData取出来,为什么就是空了呢?还有,我在login里面把cook设定到100年后过期,我取得时候,怎么又是立刻过期呢?

解决方案 »

  1.   

    你是直接读Cookie,我是把Page.User.Identity先强行转为FormsIdentity,然后从里面读出UserData.工作正常.我是在MSDN里找到的例子.PS:现在MSDN越来越不好用了,有用的信息都藏的很深.
      

  2.   

    现在MSDN越来越不好用了,有用的信息都藏的很深
    ----------------
    从来msdn都是这样
      

  3.   

    UserData 为什么空呢? 我操ms,mabi,我日他娘
      

  4.   

    public static string GetCurrentUserData()
    {
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    return 0;
       FormsIdentity useridentity = (FormsIdentity)(HttpContext.Current.User.Identity);
    string userdatastr = useridentity.Ticket.UserData;
    return userdatastr;
    }
      

  5.   

    就是这样啊,但userData 就是空啊
      

  6.   

    设置cookies的path属性就可以了,多域名共享就设置域名一下就可以了,哈哈,给分