// We're using HttpContextBase to allow access to cookies. public async Task <string> GetCartId(ClaimsPrincipal principal, CancellationToken cancellationToken = default) { string cartSessionValue = await _session.GetStringAsync(CART_SESSION_KEY, cancellationToken); if (string.IsNullOrEmpty(cartSessionValue)) { // Generate a new random GUID using System.Guid class cartSessionValue = Guid.NewGuid().ToString(); await _session.SetStringAsync(CART_SESSION_KEY, cartSessionValue, cancellationToken); } return(cartSessionValue); }