Skip to content

Instantly share code, notes, and snippets.

@vwo-kb
Last active September 4, 2019 07:44
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/e9c1682612f7ebe3bedd0a92f78d3f10 to your computer and use it in GitHub Desktop.
Save vwo-kb/e9c1682612f7ebe3bedd0a92f78d3f10 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.Text.RegularExpressions;
namespace YourApplication.Controllers {
public class CookiesController: Controller {
[HttpGet]
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();
// Expire any VWO cookie after 10 years.
UInt64 expiry = 315360000000 UL;
option.Expires = DateTime.Now.AddMilliseconds(expiry);
// Set the cookie on root path so that it's accessible on all paths
option.Path = "/";
// Set the domain to .eTld+1 e.g. for a.abc.com eTld would be abc.com. So domain should be .abc.com. If you are not sure about what is the value in your case, you can contact the VWO support team.
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