When upgrading my .NET Core 2.2 API to .NET Core 3.1, a lot of changes were required. I had to update the Swashbuckle package and change the Startup file. I now got it running in dev with Swagger.
Once publishing to a Windows 2012 server, running on IIS, every API call returns the 307 Temporary Redirect.
In the Startup, I had to remove UseMvc and add UseEndpoints
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();
}
if (!env.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Digital Signatures V1"); });
}
app.UseMiddleware<LogContextMiddleware>();
app.UseMiddleware<CustomExceptionMiddleware>();
app.UseHttpsRedirection();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
Does anyone had an idea why I got this Redirect status?
When running it in Postman, it always returns the 307 when requesting the test server. When calling localhost, it is ok!
If you are using HTTP, check if you have this line of code in
Startup.cs
and comment out:It is basically a middleware that redirects from HTTP to HTTPS. You may add it in production if you will use HTTPS.