public static HttpActionContext CacheFirstAccessedTime(this HttpActionContext actionContext) { if ((actionContext.Response != null) && ((actionContext.Response.StatusCode == HttpStatusCode.Unauthorized) || !actionContext.GetFirstAccessedTime().HasValue)) { var cookieValue = Convert.ToBase64String(Encoding.ASCII.GetBytes(DateTime.UtcNow.ToString())); var cookie = new CookieHeaderValue(FirstAccessedTimeCookieName, cookieValue); cookie.Expires = DateTimeOffset.Now.AddDays(365); //cookie.Domain = actionContext.Request.RequestUri.Host; //cookie.Path = "/"; actionContext.Response.Headers.AddCookies(new CookieHeaderValue[] { cookie }); } return(actionContext); }