How To Enable Cross Origin Requests In ASP .NET CORE

Forums .NET CoreHow To Enable Cross Origin Requests In ASP .NET CORE
Staff asked 4 years ago

Answers (1)

Add Answer
Shaikh Hafeezjaha Marked As Accepted
Staff answered 2 years ago

Add the below code Startup.cs

services.AddCors(options =>
{
    options.AddPolicy("CorsPolicy",
         builder => builder
         .SetIsOriginAllowed((host) => true)
         .AllowAnyMethod()
         .AllowAnyHeader()
         .AllowCredentials());
});


app.UseCors("CorsPolicy");

just add this line on your controller.

[Route("api/[controller]")]
ApiController]
[EnableCors("CorsPolicy")]
public class BaseController : ControllerBase
{

}

Hope it helps you.

Subscribe

Select Categories