.Net core 6 Post请求,postman在IIS上返回404

问题描述 投票:0回答:0

我有一个这样的 Post 请求:

    [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);
    }

当我在我的本地机器上测试它时它工作正常,但是当我在我们的 IIS 服务器上发布它时 POST 不起作用。奇怪的是,我也有在本地和服务器上运行良好的 GET 方法,但我的 POST 请求都不起作用。 我有请求的 API 密钥,这是我的 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();

这是我在 Postman 中的请求 enter image description here

没有错误。好像连终点都没有到,所以只给The specified URL cannot be found

.net post iis postman httprequest
© www.soinside.com 2019 - 2024. All rights reserved.