// 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;
namespace Microsoft.AspNetCore.Antiforgery
{
///
/// Provides programmatic configuration for the antiforgery token system.
///
public class AntiforgeryOptions
{
private const string AntiforgeryTokenFieldName = "__RequestVerificationToken";
private const string AntiforgeryTokenHeaderName = "RequestVerificationToken";
private string _cookieName;
private string _formFieldName = AntiforgeryTokenFieldName;
///
/// The default cookie prefix, which is ".AspNetCore.Antiforgery.".
///
public static readonly string DefaultCookiePrefix = ".AspNetCore.Antiforgery.";
///
/// Specifies the name of the cookie that is used by the antiforgery system.
///
///
/// If an explicit name is not provided, the system will automatically generate a
/// unique name that begins with .
///
public string CookieName
{
get
{
return _cookieName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_cookieName = value;
}
}
///
/// 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 .
///
public PathString? CookiePath { get; set; }
///
/// The domain set on the cookie. By default its null which results in the "domain" attribute not being
/// set.
///
public string CookieDomain { get; set; }
///
/// Specifies the name of the antiforgery token field that is used by the antiforgery system.
///
public string FormFieldName
{
get
{
return _formFieldName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_formFieldName = value;
}
}
///
/// Specifies the name of the header value that is used by the antiforgery system. If null then
/// antiforgery validation will only consider form data.
///
public string HeaderName { get; set; } = AntiforgeryTokenHeaderName;
///
/// Specifies whether SSL is required for the antiforgery system
/// to operate. If this setting is 'true' and a non-SSL request
/// comes into the system, all antiforgery APIs will fail.
///
public bool RequireSsl { get; set; }
///
/// Specifies whether to suppress the generation of X-Frame-Options header
/// which is used to prevent ClickJacking. By default, the X-Frame-Options
/// header is generated with the value SAMEORIGIN. If this setting is 'true',
/// the X-Frame-Options header will not be generated for the response.
///
public bool SuppressXFrameOptionsHeader { get; set; }
}
}