Xor*_*ist 60 https kestrel-http-server asp.net-core-2.1
因此,随着ASP.NET Core 2.1的出现,Kestrel现在会自动在HTTP端创建一个HTTPS端点,并且默认项目模板设置为从HTTP重定向到HTTPS(这很容易撤消).
但是我的问题是......如何为我的项目完全禁用HTTPS.我已经阅读了文档,并使用了各种HTTPS配置设置,但我做的任何事情似乎都不允许我将其关闭并只运行HTTP项目.
我疯了还是只是错过了什么.我希望这很容易做到.
小智 39
如果您使用的是Visual Studio 2017,则可以执行以下操作:
这将更新launchSettings.json文件中的iisExpress设置.
Tai*_*ran 32
在Startup.cs中,删除中间件
app.UseHttpsRedirection();
Run Code Online (Sandbox Code Playgroud)
Xor*_*ist 26
原来实现我想要做的事情的正确方法是使用.UseKestrel()专门配置Kestrel并简单地指定一个地址,如下所示:
WebHost.CreateDefaultBuilder(args)
.UseKestrel(options => {
options.Listen(IPAddress.Loopback, 5080); //HTTP port
})
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
有效会覆盖默认设置,并在Kestel启动时显示此警告:
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'https://localhost:5001, http://localhost:5000'. Binding to endpoints defined in UseKestrel() instead.
Run Code Online (Sandbox Code Playgroud)
如果指定了第二个地址,它将假定使用内置开发人员证书保护地址,如下:
WebHost.CreateDefaultBuilder(args)
.UseKestrel(options => {
options.Listen(IPAddress.Loopback, 5080); //HTTP port
options.Listen(IPAddress.Loopback, 5443); //HTTPS port
})
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
您当然可以专门保护您的SSL地址,如下所述:
这对于生产设置是必要的.
joa*_*ofe 15
在Properties/launchSettings.json项目的文件中,查看密钥applicationUrl.你会发现类似的东西:
...
"applicationUrl": "https://localhost:5001;http://localhost:5000",
...
Run Code Online (Sandbox Code Playgroud)
删除https端点,它已完成.
编辑
如@Xorcist所述,该文件launchSettings.json未发布.因此,上述解决方案仅适用于开发环境.要禁用https,并且通常要在生产和开发中配置要收听的URL,您还可以执行以下操作之一:
使用--urls参数dotnet run,将具有与applicationUrlin 相同的效果launchSettings.json.例如:dotnet run --urls=http://0.0.0.0:5000,https://0.0.0.0:5001.再次,删除您不想使用的那个.
使用ASPNETCORE_URLS环境变量也可以实现同样的目的.
appsettings.json(看来这在2.0中无法完成).useUrls扩展方法也可以实现相同的目的WebHost.CreateDefaultBuilder(args).UseUrls("http://0.0.0.0:5000").我更喜欢其他解决方案,因为这些硬编码是您的应用程序端点,如果不重新编译应用程序就无法更改.Microsoft Docs中详细介绍了所有可能的选项.
Cla*_*lay 12
该dotnetCLI现在有这样一个模板。
dotnet new webapi --no-https
Run Code Online (Sandbox Code Playgroud)
小智 11
在Program.cs中,如下添加UseUrls:
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://localhost:5000")
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
并在Startup.cs中删除/注释以下内容:
app.UseHttpsRedirection();
Run Code Online (Sandbox Code Playgroud)
关闭https在于这3个变化...
属性/launchSettings.json

启动.cs

使用 ASPNET CORE 2.2,我只需将 Web 服务器 URL 设置为 http 而不是 https,然后它会自行获取。我将它作为自托管进程运行。
| 归档时间: |
|
| 查看次数: |
37927 次 |
| 最近记录: |