zoukankan      html  css  js  c++  java
  • C# Cookie工具类

    /// <summary>
    
            /// Cookies赋值
    
            /// </summary>
    
            /// <param name="strName">主键</param>
    
            /// <param name="strValue">键值</param>
    
            /// <param name="strDay">有效天数</param>
    
            /// <returns></returns>
    
            public bool setCookie(string strName, string strValue, int strDay)
    
            {
    
                try
    
                {
    
                    HttpCookie Cookie = new HttpCookie(strName);
    
                    //Cookie.Domain = ".xxx.com";//当要跨域名访问的时候,给cookie指定域名即可,格式为.xxx.com
    
                    Cookie.Expires = DateTime.Now.AddDays(strDay);
    
                    Cookie.Value = strValue;
    
                    System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);
    
                    return true;
    
                }
    
                catch
    
                {
    
                    return false;
    
                }
    
            }
    
     
    
            /// <summary>
    
            /// 读取Cookies
    
            /// </summary>
    
            /// <param name="strName">主键</param>
    
            /// <returns></returns>
    
     
    
            public string getCookie(string strName)
    
            {
    
                HttpCookie Cookie = System.Web.HttpContext.Current.Request.Cookies[strName];
    
                if (Cookie != null)
    
                {
    
                    return Cookie.Value.ToString();
    
                }
    
                else
    
                {
    
                    return null;
    
                }
    
            }
    
     
    
            /// <summary>
    
            /// 删除Cookies
    
            /// </summary>
    
            /// <param name="strName">主键</param>
    
            /// <returns></returns>
    
            public bool delCookie(string strName)
    
            {
    
                try
    
                {
    
                    HttpCookie Cookie = new HttpCookie(strName);
    
                    //Cookie.Domain = ".xxx.com";//当要跨域名访问的时候,给cookie指定域名即可,格式为.xxx.com
    
                    Cookie.Expires = DateTime.Now.AddDays(-1);
    
                    System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);
    
                    return true;
    
                }
    
                catch
    
                {
    
                    return false;
    
                }
    
            }
    
        }
    
    }
    
     
    
  • 相关阅读:
    Python网页信息采集:使用PhantomJS采集淘宝天猫商品内容
    让Scrapy的Spider更通用
    API例子:用Python驱动Firefox采集网页数据
    API例子:用Java/JavaScript下载内容提取器
    Python即时网络爬虫:API说明
    Python: xml转json
    git 更新本地代码
    数据库事务
    Python的线程、进程和协程
    Java基础语法
  • 原文地址:https://www.cnblogs.com/myblogslh/p/4774438.html
Copyright © 2011-2022 走看看