© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
84 replies
RDasher

✅ CORS: Cross-Origin Request Blocked

Hello, I'm trying to figure out how to configure CORS on my .NET Web Api Application.

The Api Application is hosted on
localhost:5000
localhost:5000
, while the ReactJS Frontend is hosted on
localhost:3000
localhost:3000
.

public static void InitializeCORS(this IServiceCollection services)
{
    var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

    services.AddCors(options =>
                {
                    options.AddPolicy(name: MyAllowSpecificOrigins,
                                        policy =>
                                        {
                                            policy.WithOrigins("http://localhost:3000/*").AllowAnyHeader().AllowAnyMethod();
                                        });
                });
}
public static void InitializeCORS(this IServiceCollection services)
{
    var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

    services.AddCors(options =>
                {
                    options.AddPolicy(name: MyAllowSpecificOrigins,
                                        policy =>
                                        {
                                            policy.WithOrigins("http://localhost:3000/*").AllowAnyHeader().AllowAnyMethod();
                                        });
                });
}


Also have defined Application to use Cors in Program.cs
app.UseCors();
app.UseCors();


I've followed this from MSDN: https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-7.0
Enable Cross-Origin Requests (CORS) in ASP.NET Core
Learn how CORS as a standard for allowing or rejecting cross-origin requests in an ASP.NET Core app.
Enable Cross-Origin Requests (CORS) in ASP.NET Core
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ OpenIddict Tokens' Availability Depends On Request's Origin
C#CC# / help
3y ago
✅ Enable CORS
C#CC# / help
2y ago
❔ CORS error
C#CC# / help
3y ago
❔ !CORS ERROR!
C#CC# / help
3y ago