C# net6 webapicore怎么取消https配置
时间: 2023-07-28 12:08:00 浏览: 103
要取消ASP.NET Core Web API应用程序的HTTPS配置,可以按照以下步骤进行:
1. 打开Web API项目的`launchSettings.json`文件。
2. 在文件中找到HTTPS配置的对象,通常名称为“WebAPIProjectName”。示例如下:
```
"WebAPIProjectName": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
```
3. 删除`launchUrl`属性中的`https`配置,只保留`http`配置,示例如下:
```
"launchUrl": "http://localhost:5000",
```
4. 保存文件并重新启动Web API项目,HTTPS配置将被取消。
另外,如果Web API应用程序使用的是Kestrel服务器,可以在`Program.cs`文件中删除`UseHttps()`方法的调用来取消HTTPS配置,示例如下:
```
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseKestrel(options =>
{
// Remove the following line to cancel HTTPS configuration
// options.Listen(IPAddress.Any, 443, listenOptions =>
// {
// listenOptions.UseHttps("certificate.pfx", "password");
// });
});
});
```