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!
HTTP 307 Temporary Redirect redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location headers. The method and the body of the original request are reused to perform the redirected request.
302 is temporary redirect, which is generated by the server whereas 307 is internal redirect response generated by the browser.
If you are using HTTP, check if you have this line of code in Startup.cs
and comment out:
// app.UseHttpsRedirection();
It is basically a middleware that redirects from HTTP to HTTPS. You may add it in production if you will use HTTPS.
I had a similar problem today (request getting 307 redirected) and it turned out to be https, and the SNI mapping in IIS.
Take a look if you can access your site with http://
It this works but not with https:// then there is your problem, most likely not with your code withhin, but some setting of IIS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With