Skip to content

Instantly share code, notes, and snippets.

@vwo-kb
Last active September 4, 2019 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vwo-kb/b7606f703e1150f01a9b014f4fd9752e to your computer and use it in GitHub Desktop.
Save vwo-kb/b7606f703e1150f01a9b014f4fd9752e to your computer and use it in GitHub Desktop.
public IActionResult SyncCookies() {
foreach(string cookieName in Request.Cookies.Keys) {
string pattern = @ "^(_vis_opt_|_vwo).*";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
Match match = regex.Match(cookieName);
if (match.Success) {
string cookieValue = Request.Cookies[cookieName];
CookieOptions option = new CookieOptions();
UInt64 expiry = 315360000000 UL;
// Expire any VWO cookies after 10 years.
// Set the cookie on root path so that it's accessible on all paths
// Set the domain to .<eTld+1>
option.Expires = DateTime.Now.AddMilliseconds(expiry);
option.Path = "/";
option.Domain = ".<eTld+1";
Response.Cookies.Append(cookieName, cookieValue, option);
}
}
Response.Headers.Add("Access-Control-Allow-Origin", "*");
return Ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment