Add the cookie IsEssential flag and feature

This commit is contained in:
Chris Ross (ASP.NET) 2017-11-16 21:27:05 -08:00
parent 9aaaefbb1b
commit ac702f6818
3 changed files with 52 additions and 0 deletions

View File

@ -72,6 +72,12 @@ namespace Microsoft.AspNetCore.Http
/// </summary>
public virtual TimeSpan? MaxAge { get; set; }
/// <summary>
/// Indicates if this cookie is essential for the application to function correctly. If true then
/// consent policy checks may be bypassed. The default value is false.
/// </summary>
public virtual bool IsEssential { get; set; }
/// <summary>
/// Creates the cookie options from the given <paramref name="context"/>.
/// </summary>
@ -99,6 +105,7 @@ namespace Microsoft.AspNetCore.Http
HttpOnly = HttpOnly,
MaxAge = MaxAge,
Domain = Domain,
IsEssential = IsEssential,
Secure = SecurePolicy == CookieSecurePolicy.Always || (SecurePolicy == CookieSecurePolicy.SameAsRequest && context.Request.IsHttps),
Expires = Expiration.HasValue ? expiresFrom.Add(Expiration.Value) : default(DateTimeOffset?)
};

View File

@ -59,5 +59,11 @@ namespace Microsoft.AspNetCore.Http
/// </summary>
/// <returns>The max-age date and time for the cookie.</returns>
public TimeSpan? MaxAge { get; set; }
/// <summary>
/// Indicates if this cookie is essential for the application to function correctly. If true then
/// consent policy checks may be bypassed. The default value is false.
/// </summary>
public bool IsEssential { get; set; }
}
}

View File

@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Http.Features
{
/// <summary>
/// Used to query, grant, and withdraw user consent regarding the storage of user
/// information related to site activity and functionality.
/// </summary>
public interface ITrackingConsentFeature
{
/// <summary>
/// Indicates if consent is required for the given request.
/// </summary>
bool IsConsentNeeded { get; }
/// <summary>
/// Indicates if consent was given.
/// </summary>
bool HasConsent { get; }
/// <summary>
/// Indicates either if consent has been given or if consent is not required.
/// </summary>
bool CanTrack { get; }
/// <summary>
/// Grants consent for this request. If the response has not yet started then
/// this will also grant consent for future requests.
/// </summary>
void GrantConsent();
/// <summary>
/// Withdraws consent for this request. If the response has not yet started then
/// this will also withdraw consent for future requests.
/// </summary>
void WithdrawConsent();
}
}