when call put, delete methods I get this error No 'Access-Control-Allow-Origin' but there is no error with get, post methods this occurs when publish on server but on my computer I don't have any errors this is code in startup file
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseCors("corsPolicy");
app.UseStaticFiles();
app.UseMvc();
}
services.AddCors(options =>
{
options.AddPolicy("corsPolicy", builder =>
{
builder.AllowAnyMethod().AllowAnyOrigin().AllowAnyHeader().AllowCredentials();
});
});
controller code
namespace ContinuationProjLast.Controllers
{
[Route("api/[controller]")]
[ApiController]
[EnableCors("corsPolicy")]
public class marksController : ControllerBase
{
private readonly ProductionRefContext _context;
public marksController(ProductionRefContext context)
{
_context = context;
}
[HttpPut("{id}")]
public async Task<IActionResult> Putmark(int id, mark mark)
{
if (id != mark.ID)
{
return BadRequest();
}
var mm = _context.mark.Where(x => x.devicemark == mark.devicemark && x.devicecategory == mark.devicecategory).FirstOrDefault();
if (mm == null)
{
_context.Entry(mark).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!markExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
else
{
return BadRequest();
}
}
the same thing happens with delete method.
Can I get any help?
CodePudding user response:
Iis server doesn't support put http verb by nature, There are additional setting needs to be done. I changed them to post verb and worked well in production
CodePudding user response:
I removed WebDAV publishing from iis , the problem has been solved