Class EnableCorsAttribute
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
stringComma-separated list of origins that are allowed to access the resource. Use "*" to allow all.
headers
stringComma-separated list of headers that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.
methods
stringComma-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
stringComma-separated list of origins that are allowed to access the resource. Use "*" to allow all.
headers
stringComma-separated list of headers that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.
methods
stringComma-separated list of methods that are supported by the resource. Use "*" to allow all. Use null or empty string to allow none.
exposedHeaders
stringComma-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
Headers
Gets the headers that are supported by the resource.
public IList<string> Headers { get; }
Property Value
Methods
Gets the methods that are supported by the resource.
public IList<string> Methods { get; }
Property Value
Origins
Gets the origins that are allowed to access the resource.
public IList<string> Origins { get; }
Property Value
PreflightMaxAge
Gets or sets the number of seconds the results of a preflight request can be cached.
public long PreflightMaxAge { get; set; }
Property Value
SupportsCredentials
Gets or sets a value indicating whether the resource supports user credentials in the request.
public bool SupportsCredentials { get; set; }
Property Value
Methods
GetCorsPolicyAsync(HttpRequestMessage, CancellationToken)
public Task<CorsPolicy> GetCorsPolicyAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
request
HttpRequestMessagecancellationToken
CancellationToken
Returns
- Task<CorsPolicy>