I am getting the following error for PUT request. Gets are working fine.
Access to fetch at from origin has been blocked by CORS policy: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response. c# .net core
The api startup class looks fine as follows. Not sure what I am missing.
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.AddDbContext<AppDbContext>(options => options.UseInMemoryDatabase(databaseName: "BethanysPieShopHRM"));
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddScoped<ICountryRepository, CountryRepository>();
services.AddScoped<IJobCategoryRepository, JobCategoryRepository>();
services.AddScoped<IEmployeeRepository, EmployeeRepository>();
services.AddCors(options =>
{
options.AddPolicy("Open", builder => builder.AllowAnyOrigin().AllowAnyHeader());
});
services.AddControllers();
//.AddJsonOptions(options => options.JsonSerializerOptions.ca);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseCors("Open");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}