123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using NIU.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- namespace CP.Common
- {
-
-
-
- public class Cookies
- {
-
-
-
- private static string _Domain = ".niu.cn";
-
-
-
- public static string _CookieAdminName = "_NIU_ADMIN";
-
-
-
- public static string _AuthorityName = "_NIU_ADMIN_Authority";
-
-
-
-
-
- public static string Get(string cookieName, string domain = ".niu.cn")
- {
- if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[cookieName] != null)
- {
-
- string value = HttpContext.Current.Request.Cookies[cookieName].Value.ToString();
- return Encryption.Get(value, _CookieAdminName);
- }
- return "";
- }
-
-
-
-
-
-
- public static void Set(string cookieName, string cookieValue, int Expires = 0, string domain = ".niu.cn")
- {
- HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
- if (cookie == null)
- {
- cookie = new HttpCookie(cookieName);
- }
- cookie.Value = Encryption.Set(cookieValue, _CookieAdminName);
-
- cookie.HttpOnly = true;
- if (Expires > 0)
- cookie.Expires = DateTime.Now.AddMinutes(Expires);
- else
- cookie.Expires = DateTime.Now.AddMinutes(60);
- HttpContext.Current.Response.AppendCookie(cookie);
- }
-
-
-
- public static void Delete(string cookieName, string domain = ".niu.cn")
- {
-
- HttpContext.Current.Response.Cookies[cookieName].Expires = DateTime.Now.AddDays(-600);
- }
-
-
-
-
- public static void RemoveCookies(string cookiesName)
- {
- if (string.IsNullOrEmpty(cookiesName))
- return;
- HttpCookie cookie = HttpContext.Current.Request.Cookies[cookiesName];
- if (null != cookie)
- {
-
- HttpContext.Current.Response.Cookies[cookiesName].Expires = DateTime.Now.AddDays(-600);
- HttpContext.Current.Response.Cookies[cookiesName].Values.Clear();
- cookie.Expires = DateTime.Now.AddDays(-5);
- HttpContext.Current.Response.Cookies.Add(cookie);
- }
- }
-
-
-
-
-
-
-
- public static void WriteCookie(string strName, string strValue, int expires = 480, bool httponly = true, string domain = ".niu.cn")
- {
- HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
- if (cookie == null)
- {
- cookie = new HttpCookie(strName);
- }
- cookie.HttpOnly = httponly;
-
- cookie.Value = HttpContext.Current.Server.UrlEncode(strValue);
- if (expires > 0)
- cookie.Expires = DateTime.Now.AddMinutes(expires);
- HttpContext.Current.Response.Cookies.Add(cookie);
- }
- public static string GetCookieBy(string strName, string domain = ".niu.cn")
- {
- if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
- {
-
- return HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies[strName].Value.ToString());
- }
- return "";
- }
- }
- }
|