I have a Post request like this:
[HttpPost("storesubmission")]
public async Task<IActionResult> StoreSubmission([FromBody]TestModel tModel)
{
mt.name = tModel.name;
mt.age = tModel.age;
mt.submittedBy = tModel.submittedBy;
mt.submittedAt = tModel.submittedAt;
mt.province = tModel.province;
mt.tractId = tModel.tractId;
mt.referenceNumber = tModel.referenceNumber;
_context.TestModels.Add(mt);
await _context.SaveChangesAsync();
return Ok(mt);
}
When I test it on my local machine it works fine, but when I publish it on our IIS server the POST doesn't work. The strange thing is that I also have GET methods that work fine on local and Server, but none of my POST requests work. I have an API key for the request and here is my Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<DataContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("ProntoConnection"));
});
var corsPolicy = "_corsPolicy";
builder.Services.AddCors(options =>
{
options.AddPolicy(corsPolicy,
policy =>
{
policy
.WithOrigins("https://example.com")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors(corsPolicy);
app.UseAuthentication();
app.UseAuthorization();
app.UseHttpsRedirection();
app.UseMiddleware<ApiKeyMiddleware>();
app.MapControllers();
app.Run();
Here is my request in Postman
There are no errors. It seems like it doesn't even reach the endpoint, so it only gives The specified URL cannot be found.
This was a firewall issue. The company firewall was blocking the request.