• Cookie辅助类


     1     /// <summary>
     2     /// Cookie辅助类
     3     /// </summary>
     4     public class CookieHelper
     5     {
     6         /// <summary>
     7         /// 清除指定Cookie
     8         /// </summary>
     9         /// <param name="cookiename">cookiename</param>
    10         public static void ClearCookie(string cookiename)
    11         {
    12             HttpCookie cookie = HttpContext.Current.Request.Cookies[cookiename];
    13             if (cookie != null)
    14             {
    15                 cookie.Expires = DateTime.Now.AddYears(-3);
    16                 HttpContext.Current.Response.Cookies.Add(cookie);
    17             }
    18         }
    19 
    20         /// <summary>
    21         /// 获取指定Cookie值
    22         /// </summary>
    23         /// <param name="cookiename">cookiename</param>
    24         /// <returns></returns>
    25         public static string GetCookieValue(string cookiename)
    26         {
    27             HttpCookie cookie = HttpContext.Current.Request.Cookies[cookiename];
    28             string str = string.Empty;
    29             if (cookie != null)
    30             {
    31                 str = cookie.Value;
    32             }
    33             return str;
    34         }
    35 
    36         /// <summary>
    37         /// 添加一个Cookie(24小时过期)
    38         /// </summary>
    39         /// <param name="cookiename"></param>
    40         /// <param name="cookievalue"></param>
    41         public static void SetCookie(string cookiename, string cookievalue)
    42         {
    43             SetCookie(cookiename, cookievalue, DateTime.Now.AddDays(1.0));
    44         }
    45 
    46         /// <summary>
    47         /// 添加一个Cookie
    48         /// </summary>
    49         /// <param name="cookiename">cookie名</param>
    50         /// <param name="cookievalue">cookie值</param>
    51         /// <param name="expires">过期时间 DateTime</param>
    52         public static void SetCookie(string cookiename, string cookievalue, DateTime expires)
    53         {
    54             HttpCookie cookie = new HttpCookie(cookiename)
    55             {
    56                 Value = cookievalue,
    57                 Expires = expires
    58             };
    59             HttpContext.Current.Response.Cookies.Add(cookie);
    60         }
    61     }
  • 相关阅读:
    alpha冲刺—Day5
    alpha冲刺—Day4
    alpha冲刺—Day3
    alpha冲刺—Day2
    alpha冲刺—Day1
    团队作业第五次—alpha冲刺博客汇总
    团队作业第四次—项目系统设计与数据库设计
    团队作业第三次—项目需求分析
    团队作业第二次—团队Github实战训练
    win10配置java环境变量,解决javac不是内部或外部命令等问题
  • 原文地址:https://www.cnblogs.com/xzitluyang/p/5898661.html
Copyright © 2020-2023  润新知