zoukankan      html  css  js  c++  java
  • asp.net cookie读写

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;

        public class UserState
        {
            /// <summary>
            /// 写cookie值
            /// </summary>
            /// <param name="strName">名称</param>
            /// <param name="strValue">值</param>
            public static void WriteCookie(string strName, string strValue)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
                if (cookie == null)
                {
                    cookie = new HttpCookie(strName);
                }
                cookie.Value = strValue;
                HttpContext.Current.Response.AppendCookie(cookie);
            }
            /// <summary>
            /// 写cookie值
            /// </summary>
            /// <param name="strName">名称</param>
            /// <param name="strValue">值</param>
            /// <param name="strValue">过期时间(分钟)</param>
            public static void WriteCookie(string strName, string strValue, int expires)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
                if (cookie == null)
                {
                    cookie = new HttpCookie(strName);
                }
                cookie.Value = strValue;
                cookie.Expires = DateTime.Now.AddMinutes(expires);
                HttpContext.Current.Response.AppendCookie(cookie);
            }
            /// <summary>
            /// 读cookie值
            /// </summary>
            /// <param name="strName">名称</param>
            /// <returns>cookie值</returns>
            public static string GetCookie(string strName)
            {
                if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
                {
                    return HttpContext.Current.Request.Cookies[strName].Value.ToString();
                }
                return "";
            }
        }

  • 相关阅读:
    cxgrid动态创建列
    cxgrid显示海量数据
    Delphi 两个应用程序(进程)之间的通信
    Delphi实现窗体内嵌其他应用程序窗体
    Change tab position of PageControl to bottom
    how can I make the login form transparent?
    UniDBGrid增加显示记录数的label及隐藏refresh按钮
    java工厂模式实例化class
    Java 语言细节
    applet示例 WelcomeApplet.java <Core Java>
  • 原文地址:https://www.cnblogs.com/stulife/p/1759754.html
Copyright © 2011-2022 走看看