HI WELCOME TO KANSIRIS

Enable CORS in ASP.NET Core

Leave a Comment
Step 1: Add below code in ConfigureServices(IServiceCollection services) in Startup.cs
1
2
3
4
5
6
7
8
services.AddCors(options =>
{
    options.AddPolicy("CorsPolicy",
        builder => builder.AllowAnyOrigin()
        .AllowAnyMethod()
        .AllowAnyHeader()
        .AllowCredentials() );
});
Step 2: Add below code in Configure(IApplicationBuilder app) in Startup.cs
1
app.UseCors("CorsPolicy");
Step 3: Add [EnableCors(“CorsPolicy”)] in Controller level or Action level

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.