当前位置: 代码迷 >> ASP.NET >> Cookies操作基类 user治理基类
  详细解决方案

Cookies操作基类 user治理基类

热度:2883   发布时间:2013-02-25 00:00:00.0
Cookies操作基类 user管理基类
登录存取的一些基类  和cookies操作    有官网的最好,,要规范的 

------解决方案--------------------------------------------------------
引用:
登录存取的一些基类  和cookies操作    有官网的最好,,要规范的

Cookie Helper C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PAB.Web
{
        public static class CookieUtil
        {

        public static string GetCookieValue (string cookieName)
        {
          string cookieVal = String.Empty;
            cookieVal = HttpContext.Current.Request.Cookies[cookieName].Value;
           return cookieVal;
        }

        public static void CreateCookie (string cookieName, string value, int? expirationDays)
        {
            HttpCookie Cookie = new HttpCookie(cookieName, value);
             if ( expirationDays.HasValue )
                Cookie.Expires = DateTime.Now.AddDays(expirationDays.Value );
             HttpContext.Current.Response.Cookies.Add(Cookie);
        }

         public static void DeleteCookie (string cookieName)
        {
            HttpCookie Cookie = HttpContext.Current.Request.Cookies[cookieName];
             if (Cookie != null)
            {
                Cookie.Expires = DateTime.Now.AddDays(-2);
                 HttpContext.Current.Response.Cookies.Add(Cookie);
             }
        }

        public static bool CookieExists(string cookieName)
        {
            bool exists = false;
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
             if (cookie != null)
                exists = true;
            return exists;
  相关解决方案