• 动态设置Cookies过期时间


                  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);

  • 相关阅读:
    模板为webpack的目录结构
    实例和内置组件
    微信小程序之富文本解析
    微信小程序获取输入框(input)内容
    for循环的语法和执行顺序
    循环
    选择结构(二)
    选择结构
    算术运算
    变量
  • 原文地址:https://www.cnblogs.com/zpq521/p/1159519.html
Copyright © 2020-2023  润新知