- 1 year ago
Disable https dotnet core 3.0 webapi
Comment
1 / 1
To disable HTTPS in a .NET Core 3.0 Web API application, you can modify the CreateWebHostBuilder
method in the Program.cs
file.
By default, .NET Core 3.0 enables HTTPS redirection and requires HTTPS for all requests. To disable HTTPS, you can remove the call to UseHttpsRedirection
and update the UseUrls
method to specify only the HTTP URL.
Here's an example:
csharpusing Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace YourNamespace
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls("http://localhost:5000"); // Specify HTTP URL
webBuilder.ConfigureKestrel(options =>
{
options.ListenAnyIP(5000); // Listen on port 5000
});
webBuilder.UseStartup<Startup>();
//webBuilder.UseHttpsRedirection(); // Remove this line to disable HTTPS redirection
});
}
}
By removing the call to UseHttpsRedirection
, you disable the automatic redirection to HTTPS.
Additionally, make sure to update the URL in the UseUrls
method to match your desired HTTP URL.
After making these changes, your .NET Core 3.0 Web API application will only use HTTP and won't enforce HTTPS.