Cross-Origin Resource Sharing (CORS) configuration for controlling access from different origins.
{
"Cors": {
"Enabled": false,
"AllowedOrigins": [],
"AllowedMethods": ["*"],
"AllowedHeaders": ["*"],
"AllowCredentials": false,
"PreflightMaxAgeSeconds": 600
}
}Specify which origins can make cross-origin requests:
{
"Cors": {
"Enabled": true,
"AllowedOrigins": [
"https://example.com",
"https://app.example.com"
]
}
}::: warning
An empty AllowedOrigins array allows no origins. You must specify at least one origin when CORS is enabled.
:::
To allow requests from any origin (not recommended for production with credentials):
{
"Cors": {
"Enabled": true,
"AllowedOrigins": ["*"],
"AllowCredentials": false
}
}::: danger
Using "*" for origins with AllowCredentials: true is not allowed by browsers and will cause CORS errors.
:::
Specify which HTTP methods are permitted:
{
"Cors": {
"AllowedMethods": ["GET", "POST", "PUT", "DELETE"]
}
}Use ["*"] to allow all methods.
Specify which request headers are permitted:
{
"Cors": {
"AllowedHeaders": ["Content-Type", "Authorization", "X-Requested-With"]
}
}Use ["*"] to allow all headers.
When AllowCredentials is true, the browser includes cookies and authorization headers in cross-origin requests. This requires specific origins (not "*").
::: warning Default changed in 3.17.0
AllowCredentials now defaults to false. Credentials in cross-origin requests must be enabled deliberately, and only together with an explicit AllowedOrigins list. If you relied on the old default, set "AllowCredentials": true explicitly.
:::
The PreflightMaxAgeSeconds setting controls how long browsers cache preflight (OPTIONS) request responses. Higher values reduce preflight requests but delay CORS policy changes from taking effect.
Production configuration with specific origins:
{
"Cors": {
"Enabled": true,
"AllowedOrigins": [
"https://myapp.com",
"https://admin.myapp.com"
],
"AllowedMethods": ["GET", "POST", "PUT", "DELETE"],
"AllowedHeaders": ["Content-Type", "Authorization"],
"AllowCredentials": true,
"PreflightMaxAgeSeconds": 3600
}
}Development configuration allowing all origins:
{
"Cors": {
"Enabled": true,
"AllowedOrigins": ["*"],
"AllowedMethods": ["*"],
"AllowedHeaders": ["*"],
"AllowCredentials": false,
"PreflightMaxAgeSeconds": 600
}
}- Comment Annotations Guide - How annotations work
- Configuration Guide - How configuration works
- Server & SSL - Configure HTTPS and Kestrel web server
- Authentication - Configure authentication methods
