• Cookie


                  DateTime dt = DateTime.Now;
                    switch (dropSaveDate.SelectedValue)//dropSaveDate为
                    {
                        case "2小时":
                            dt = DateTime.Now.AddMinutes(120);//二小时过期
                            break;
                        case"一天":
                            dt = DateTime.Now.AddDays(1);
                            break;
                        case"一周":
                            dt = DateTime.Now.AddDays(7);
                            break;
                        case"一月":
                            dt = DateTime.Now.AddMonths(1);
                            break;
                        default:
                            break;
                    }
                    // 创建身份验证票证
                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket (                                                              

                                           1, // version
                                           gUserId, // user name
                                           DateTime.Now, // 开始时间
                                           dt,// 过期时间为一   //天:DateTime.Now.AddDays(1)
                                           true, // 持久性,若为True,需设置,Cookies的Expires属性,若为False,则关闭浏览器就会失效
                                            ""// User data

    );             

        string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    // 创建Cookie
        HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
        authCookie.Expires = authTicket.Expiration;

        Response.Cookies.Add(authCookie);
  • 相关阅读:
    第七十天 how can I 坚持
    第六十九天 how can I 坚持
    第六十八天 how can I 坚持
    第六十七天 how can I 坚持 (补昨天)
    第六十六天 how can I 坚持··
    第六十五天 how can I 坚持
    第六十四天 how can i 坚持
    第六十三天 how can I 坚持
    MyEclipse10 中的两种FreeMarker插件的安装与配置
    画板社交工具开发分享——HTML5 canvas控件、PHP、社交分享学习(四)
  • 原文地址:https://www.cnblogs.com/tommyli/p/1159541.html
Copyright © 2020-2023  润新知