puzi0315
/// <summary>
    /// 沐雪微淘小程序商城
    /// cookie设置
    /// </summary>
    public static class CookieHelper
    {
        private static HttpResponse CurrentResponse
        {
            get
            {
                return AppHttpContext.Current.Response;
            }
        }
        private static HttpRequest CurrentRequest
        {
            get
            {
                return AppHttpContext.Current.Request;
            }
        }
        public static void Add(string key, string value, int minutes = 30)
        {
            CurrentRequest.Cookies.TryGetValue(key, out string tmpvalue);
            if (!string.IsNullOrEmpty(tmpvalue))
            {
                CurrentResponse.Cookies.Delete(key);
            }
            CurrentResponse.Cookies.Append(key, value, new CookieOptions
            {
                Expires = DateTime.Now.AddMinutes(minutes)
            });
        }

        public static void Delete(string key)
        {
            CurrentResponse.Cookies.Delete(key);
        }
        /// <summary>
        /// 获取cookies
        /// </summary>
        /// <param name="key"></param>
        /// <returns>返回对应的值</returns>
        public static string GetCookies(string key)
        {
            CurrentRequest.Cookies.TryGetValue(key, out string value);
            if (string.IsNullOrEmpty(value))
                value = string.Empty;
            return value;

        }

代码如上,非常简单;AppHttpContext的封装,请看我上一篇文章https://www.cnblogs.com/puzi0315/p/13337279.html

 

分类:

技术点:

相关文章:

  • 2021-10-16
  • 2022-02-05
  • 2021-06-25
  • 2022-12-23
  • 2021-11-09
  • 2020-06-23
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2022-12-23
  • 2021-05-30
  • 2021-08-13
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案