using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Text; namespace Admin.Core.Common { /// /// Cookie辅助类 /// public static class CookieHelper { public static void SetCookies(this HttpContext httpContext, string key, string value, int minutes = 30) { httpContext.Response.Cookies.Append(key, value, new CookieOptions { Expires = DateTime.Now.AddMinutes(minutes), HttpOnly = true, Secure = true, IsEssential = true, }); } public static void DeleteCookies(this HttpContext httpContext, string key) { httpContext.Response.Cookies.Delete(key); } public static string GetCookies(this HttpContext httpContext, string key) { httpContext.Request.Cookies.TryGetValue(key, out string value); return value ?? string.Empty; } } }