using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WX.CRM.WEB.Handler { public static class ResponseExtend { public static void SetCookie(this HttpResponseBase response, string key, string value, SameSiteMode sameSite = SameSiteMode.None, bool requireSSL = false) { string sameSiteValue = string.Empty; string secureValue = string.Empty; switch (sameSite) { case SameSiteMode.Strict: sameSiteValue = " SameSite=Strict;"; break; case SameSiteMode.Lax: sameSiteValue = " SameSite=Lax;"; break; case SameSiteMode.None: default: sameSiteValue = " SameSite=None;"; break; } if (requireSSL) { secureValue = " Secure"; } response.Headers.Add("set-cookie", string.Format($"{key}={value}; path=/;{sameSiteValue}{secureValue}")); } } public enum SameSiteMode { Strict, Lax, None } }