Skip to content

Commit e806756

Browse files
Copilottdykstra
andcommitted
Fix CORS wildcard subdomain documentation and code samples
Co-authored-by: tdykstra <[email protected]>
1 parent ef1acf6 commit e806756

File tree

7 files changed

+10
-9
lines changed

7 files changed

+10
-9
lines changed

aspnetcore/security/cors.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
title: Enable Cross-Origin Requests (CORS) in ASP.NET Core
3+
ai-usage: ai-assisted
34
author: tdykstra
45
description: Learn how CORS as a standard for allowing or rejecting cross-origin requests in an ASP.NET Core app.
56
ms.author: tdykstra
67
ms.custom: mvc
7-
ms.date: 09/29/2025
8+
ms.date: 11/10/2025
89
uid: security/cors
910
---
1011
# Enable Cross-Origin Requests (CORS) in ASP.NET Core
@@ -211,7 +212,7 @@ This section describes the various options that can be set in a CORS policy:
211212

212213
[!code-csharp[](~/security/cors/8.0sample/Cors/Web2API/Program.cs?name=snippet_aa)]
213214

214-
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the base origin `"https://example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The wildcard matching is handled by the method, so the origin should be specified without the `*` wildcard character.
215+
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the wildcard origin `"https://*.example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The `*` wildcard character must be included in the origin to enable wildcard subdomain matching.
215216

216217
### Set the allowed HTTP methods
217218

aspnetcore/security/cors/3.1sample/Cors/WebAPI/StartupAllowSubdomain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void ConfigureServices(IServiceCollection services)
2727
options.AddPolicy("MyAllowSubdomainPolicy",
2828
policy =>
2929
{
30-
policy.WithOrigins("https://example.com")
30+
policy.WithOrigins("https://*.example.com")
3131
.SetIsOriginAllowedToAllowWildcardSubdomains();
3232
});
3333
#endregion

aspnetcore/security/cors/6.0sample/Cors/WebAPI/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
options.AddPolicy(name: MyAllowSpecificOrigins,
260260
policy =>
261261
{
262-
policy.WithOrigins("https://example.com")
262+
policy.WithOrigins("https://*.example.com")
263263
.SetIsOriginAllowedToAllowWildcardSubdomains();
264264
});
265265
});

aspnetcore/security/cors/8.0sample/Cors/Web2API/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
options.AddPolicy(name: MyAllowSpecificOrigins,
262262
policy =>
263263
{
264-
policy.WithOrigins("https://example.com")
264+
policy.WithOrigins("https://*.example.com")
265265
.SetIsOriginAllowedToAllowWildcardSubdomains();
266266
});
267267
});

aspnetcore/security/cors/includes/cors56.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ This section describes the various options that can be set in a CORS policy:
206206

207207
[!code-csharp[](~/security/cors/6.0sample/Cors/WebAPI/Program.cs?name=snippet_aa)]
208208

209-
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the base origin `"https://example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The wildcard matching is handled by the method, so the origin should be specified without the `*` wildcard character.
209+
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the wildcard origin `"https://*.example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The `*` wildcard character must be included in the origin to enable wildcard subdomain matching.
210210

211211
### Set the allowed HTTP methods
212212

@@ -823,7 +823,7 @@ This section describes the various options that can be set in a CORS policy:
823823

824824
[!code-csharp[](~/security/cors/3.1sample/Cors/WebAPI/StartupAllowSubdomain.cs?name=snippet)]
825825

826-
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the base origin `"https://example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The wildcard matching is handled by the method, so the origin should be specified without the `*` wildcard character.
826+
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the wildcard origin `"https://*.example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The `*` wildcard character must be included in the origin to enable wildcard subdomain matching.
827827

828828
### Set the allowed HTTP methods
829829

aspnetcore/security/cors/includes/cors7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ This section describes the various options that can be set in a CORS policy:
207207

208208
[!code-csharp[](~/security/cors/8.0sample/Cors/Web2API/Program.cs?name=snippet_aa)]
209209

210-
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the base origin `"https://example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The wildcard matching is handled by the method, so the origin should be specified without the `*` wildcard character.
210+
In the preceding code, `SetIsOriginAllowedToAllowWildcardSubdomains` is called with the wildcard origin `"https://*.example.com"`. This configuration allows CORS requests from any subdomain of `example.com`, such as `https://subdomain.example.com` or `https://api.example.com`. The `*` wildcard character must be included in the origin to enable wildcard subdomain matching.
211211

212212
### Set the allowed HTTP methods
213213

aspnetcore/security/cors/sample/CorsExample4/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void ConfigureServices(IServiceCollection services)
100100
options.AddPolicy("AllowSubdomain",
101101
policy =>
102102
{
103-
policy.WithOrigins("https://example.com")
103+
policy.WithOrigins("https://*.example.com")
104104
.SetIsOriginAllowedToAllowWildcardSubdomains();
105105
});
106106
// END11

0 commit comments

Comments
 (0)