private void PopulateCollectionFromSecureCookie(string cookieName, IMultiMap <string, string> map) { var item = this.GetCookieByName(cookieName); var cookieValue = this.GetValueFromCookie(item); if (string.IsNullOrWhiteSpace(cookieValue)) { return; } var builder = new UriBuilder("http://domain.com" + cookieValue); string serializedCollection = builder.Query.TrimStart('?'); var path = builder.Path; string checkSum = path.StartsWith(this.Prefix(), StringComparison.Ordinal) ? path.Substring(this.Prefix().Length) : string.Empty; if (checkSum != this.GenerateCompositeHash(cookieName, serializedCollection)) { return; } UrlEncodingExtender.ParseValue(map, serializedCollection); }
public void SetSecureCookieValues(string cookieName, IReadOnlyMultiMap <string, string> secureCollection) { secureCollection.Validate().IsNotNull(); if (secureCollection.Count == 0) { this.DeleteCookie(cookieName); } else { var serializedCollection = UrlEncodingExtender.Write(secureCollection); var checkSum = this.GenerateCompositeHash(cookieName, serializedCollection); this.SetCookie(cookieName, string.Concat(this.Prefix(), checkSum, "?", serializedCollection)); } }