Inject the service into the configureservices function of the startup file
public void ConfigureServices(IServiceCollection services)
{
#Region CORS cross domain request
services.AddCors(c =>
{
c.AddPolicy("AllRequests", policy =>
{
policy
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
#endregion
services.AddControllers();
}
Start the middleware in the following configure function
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
//Open CORS cross domain request Middleware
app.UseCors("AllRequests");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}