如何在ASP.NET Core 2.1 + Kestrel中禁用HTTPS? [英] How do I disable HTTPS in ASP.NET Core 2.1 + Kestrel?

查看:94
本文介绍了如何在ASP.NET Core 2.1 + Kestrel中禁用HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,随着ASP.NET Core 2.1的出现,Kestrel现在自动在HTTP旁边创建一个HTTPS终结点,并且默认项目模板已设置为从HTTP重定向到HTTPS(很容易撤消).

So it appears with the advent of ASP.NET Core 2.1, Kestrel now automatically creates an HTTPS endpoint along side the HTTP one, and default project templates are setup to redirect from HTTP to HTTPS (which is easy enough to undo).

但是我的问题是...如何为我的项目完全禁用HTTPS.我已经阅读了文档,并使用了HTTPS的各种配置设置,但似乎没有什么允许我关闭它并只运行HTTP项目.

However my question is... how can I disable HTTPS entirely for my project. I've read through the docs and played with a variety of config settings for HTTPS but nothing I do seems to allow me to turn it off and just run an HTTP project.

我疯了还是只想念点东西.我希望这非常容易做到.

Am I crazy or just missing something. I would expect this to be super easy to do.

推荐答案

找出实现我想要做的正确方法,就是使用.UseKestrel()专门配置Kestrel并简单地指定一个地址,如下所示:

Turns out the proper way to achieve what I wanted to do, was to specifically configure Kestrel with .UseKestrel() and simply specify a single address, like this:

  WebHost.CreateDefaultBuilder(args)
    .UseKestrel(options => {
      options.Listen(IPAddress.Loopback, 5080); //HTTP port
    })
    .UseStartup<Startup>();

影响覆盖默认设置,并在Kestel启动时显示此警告:

in affect overriding the default setup, and displaying this warning when Kestel starts:

warn: Microsoft.AspNetCore.Server.Kestrel[0]
  Overriding address(es) 'https://localhost:5001, http://localhost:5000'. Binding to endpoints defined in UseKestrel() instead.

如果指定了第二个地址,则将假定该地址将使用内置的开发者证书进行保护,例如:

if a second address is specified it will assume that address is to be secured with the built-in developer cert, as such:

  WebHost.CreateDefaultBuilder(args)
    .UseKestrel(options => {
      options.Listen(IPAddress.Loopback, 5080); //HTTP port
      options.Listen(IPAddress.Loopback, 5443); //HTTPS port
    })
    .UseStartup<Startup>();

您当然可以按照以下说明专门保护您的SSL地址:

you may of course specifically secure your SSL address as described here:

https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/servers/kestrel?view = aspnetcore-2.1& tabs = aspnetcore2x

这是生产设置所必需的.

which is necessary for production setups.

这篇关于如何在ASP.NET Core 2.1 + Kestrel中禁用HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆