Table of Contents

Class EnableCorsAttribute

Namespace
System.Web.Http.Cors
Assembly
System.Web.Http.Cors.dll

This class defines an attribute that can be applied to an action or a controller to enable CORS. By default, it allows all origins, methods and headers.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = false)]
public sealed class EnableCorsAttribute : Attribute, ICorsPolicyProvider
Inheritance
EnableCorsAttribute
Implements
Inherited Members

Constructors

EnableCorsAttribute(string, string, string)

Initializes a new instance of the EnableCorsAttribute class.

public EnableCorsAttribute(string origins, string headers, string methods)

Parameters

origins string

Comma-separated list of origins that are allowed to access the resource. Use "*" to allow all.

headers string

Comma-separated list of headers that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.

methods string

Comma-separated list of methods that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.

EnableCorsAttribute(string, string, string, string)

Initializes a new instance of the EnableCorsAttribute class.

public EnableCorsAttribute(string origins, string headers, string methods, string exposedHeaders)

Parameters

origins string

Comma-separated list of origins that are allowed to access the resource. Use "*" to allow all.

headers string

Comma-separated list of headers that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.

methods string

Comma-separated list of methods that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.

exposedHeaders string

Comma-separated list of headers that the resource might use and can be exposed. Use null or empty string to expose none.

Properties

ExposedHeaders

Gets the headers that the resource might use and can be exposed.

public IList<string> ExposedHeaders { get; }

Property Value

IList<string>

Headers

Gets the headers that are supported by the resource.

public IList<string> Headers { get; }

Property Value

IList<string>

Methods

Gets the methods that are supported by the resource.

public IList<string> Methods { get; }

Property Value

IList<string>

Origins

Gets the origins that are allowed to access the resource.

public IList<string> Origins { get; }

Property Value

IList<string>

PreflightMaxAge

Gets or sets the number of seconds the results of a preflight request can be cached.

public long PreflightMaxAge { get; set; }

Property Value

long

SupportsCredentials

Gets or sets a value indicating whether the resource supports user credentials in the request.

public bool SupportsCredentials { get; set; }

Property Value

bool

Methods

GetCorsPolicyAsync(HttpRequestMessage, CancellationToken)

public Task<CorsPolicy> GetCorsPolicyAsync(HttpRequestMessage request, CancellationToken cancellationToken)

Parameters

request HttpRequestMessage
cancellationToken CancellationToken

Returns

Task<CorsPolicy>