// 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.
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Microsoft.AspNetCore.Mvc
{
///
/// Provides programmatic configuration for cookies set by
///
public class CookieTempDataProviderOptions
{
private CookieBuilder _cookieBuilder = new CookieBuilder
{
Name = CookieTempDataProvider.CookieName,
HttpOnly = true,
// Check the comment on CookieBuilder below for more details
SameSite = SameSiteMode.Lax,
// This cookie has been marked as non-essential because a user could use the SessionStateTempDataProvider,
// which is more common in production scenarios. Check the comment on CookieBuilder below
// for more information.
IsEssential = false,
// Some browsers do not allow non-secure endpoints to set cookies with a 'secure' flag or overwrite cookies
// whose 'secure' flag is set (http://httpwg.org/http-extensions/draft-ietf-httpbis-cookie-alone.html).
// Since mixing secure and non-secure endpoints is a common scenario in applications, we are relaxing the
// restriction on secure policy on some cookies by setting to 'None'. Cookies related to authentication or
// authorization use a stronger policy than 'None'.
SecurePolicy = CookieSecurePolicy.None,
};
///
///
/// Determines the settings used to create the cookie in .
///
///
/// defaults to . Setting this to
/// may cause browsers to not send back the cookie to the server in an
/// OAuth login flow.
/// defaults to .
/// defaults to true.
/// defaults to false, This property is only considered when a
/// user opts into the CookiePolicyMiddleware. If you are using this middleware and want to use
/// , then either set this property to true or
/// request user consent for non-essential cookies.
///
///
public CookieBuilder Cookie
{
get => _cookieBuilder;
set => _cookieBuilder = value ?? throw new ArgumentNullException(nameof(value));
}
#region Obsolete API
///
///
/// This property is obsolete and will be removed in a future version. The recommended alternative is on .
///
///
/// The path set on the cookie. If set to null, the "path" attribute on the cookie is set to the current
/// request's value. If the value of is
/// null or empty, then the "path" attribute is set to the value of .
///
///
[Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Path) + ".")]
public string Path { get => Cookie.Path; set => Cookie.Path = value; }
///
///
/// This property is obsolete and will be removed in a future version. The recommended alternative is on .
///
///
/// The domain set on a cookie. Defaults to null.
///
///
[Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Domain) + ".")]
public string Domain { get => Cookie.Domain; set => Cookie.Domain = value; }
///
///
/// This property is obsolete and will be removed in a future version. The recommended alternative is on .
///
///
/// The name of the cookie which stores TempData. Defaults to .
///
///
[Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Name) + ".")]
public string CookieName { get; set; } = CookieTempDataProvider.CookieName;
#endregion
}
}