diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs b/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs
index 203a7a0402..ce89e5b054 100644
--- a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs
+++ b/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs
@@ -72,6 +72,12 @@ namespace Microsoft.AspNetCore.Http
///
public virtual TimeSpan? MaxAge { get; set; }
+ ///
+ /// 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.
+ ///
+ public virtual bool IsEssential { get; set; }
+
///
/// Creates the cookie options from the given .
///
@@ -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?)
};
diff --git a/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs b/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs
index e01a759c8f..27141a32f2 100644
--- a/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs
+++ b/src/Microsoft.AspNetCore.Http.Features/CookieOptions.cs
@@ -59,5 +59,11 @@ namespace Microsoft.AspNetCore.Http
///
/// The max-age date and time for the cookie.
public TimeSpan? MaxAge { get; set; }
+
+ ///
+ /// 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.
+ ///
+ public bool IsEssential { get; set; }
}
}
diff --git a/src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs b/src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs
new file mode 100644
index 0000000000..9e5108db43
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.cs
@@ -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
+{
+ ///
+ /// Used to query, grant, and withdraw user consent regarding the storage of user
+ /// information related to site activity and functionality.
+ ///
+ public interface ITrackingConsentFeature
+ {
+ ///
+ /// Indicates if consent is required for the given request.
+ ///
+ bool IsConsentNeeded { get; }
+
+ ///
+ /// Indicates if consent was given.
+ ///
+ bool HasConsent { get; }
+
+ ///
+ /// Indicates either if consent has been given or if consent is not required.
+ ///
+ bool CanTrack { get; }
+
+ ///
+ /// Grants consent for this request. If the response has not yet started then
+ /// this will also grant consent for future requests.
+ ///
+ void GrantConsent();
+
+ ///
+ /// Withdraws consent for this request. If the response has not yet started then
+ /// this will also withdraw consent for future requests.
+ ///
+ void WithdrawConsent();
+ }
+}