Asp.Net Core 2.0 HTTP->Kestrel上的HTTPS [英] Asp.Net Core 2.0 HTTP -> HTTPS on Kestrel

查看:59
本文介绍了Asp.Net Core 2.0 HTTP->Kestrel上的HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习基于Web的编程,目前选择在Asp.Net Core 2.0上工作.我已经成功创建了一个由2层Controller Home& amp;层组成的Web应用程序.API.主控制器直接与我的视图交互,而API控制器是通过主控制器中的GetAsync,PostAsync,PutAsync等调用的.最近,我决定将此应用程序移至HTTPS.了解了自签名证书,并成功运行了该证书,但无法访问我的API.

I am learning Web-Based Programming and currently chose to work on Asp.Net Core 2.0. I had successfully created a Web App with 2 layers of Controllers Home & API. The Home Controller interacts directly with my Views while the API controller is called using GetAsync, PostAsync, PutAsync, etc. from my Home controller. Recent I decided to move this app into HTTPS. Learned about self-signed certificates and had successfully gotten it to run except my API becomes inaccessible.

关闭SSL后,我仍然可以使用Postman调用我的API.

With SSL switched off, I could still call my API with Postman.

我以前使用以下URI来调用我的API: http://localhost:5667/api/WebApi .

I used to call my API using this URI: http://localhost:5667/api/WebApi.

  var response = client.GetAsync("SomeApi")
    response.Wait();

现在我尝试使用URI: https://localhost:5667/api/WebApi 但会中断在 response.Wait().

Now I tried using URI: https://localhost:5667/api/WebApi but breaks at response.Wait().

请提供任何建议.预先感谢

Any advice, please. Thanks in advance

根据要求:这是我的Startup.cs的一部分

As requested: here’s a portion of my Startup.cs

services.AddMvc(
   options =>
   {
       options.SslPort=5667;
       options.Filters.Add(new RequireHttpsAttribute());
    }
 );

 services.AddAntiforgery(
  options => 
  {
        options.Cookie.Name="_af";
        options.Cookie.HttpOnly = true;
        options.Cookie.SecurePolicy=CookieSecurePolicy.Always;
        options.HeaderName="X-XSRF-TOKEN";
     }
   )

推荐答案

HTTP和HTTPS不能通过同一端口提供.如果您的本地主机HTTP端点在5667上,那么您的HTTPS端点可能在5668上-尽管您可以在Kestrel将在启动时登录的信息中自行检查端口号.

HTTP and HTTPS cannot be served over the same port. If your localhost HTTP endpoint is on 5667, then likely your HTTPS endpoint is on 5668 - though you can check the port number for yourself in the info that Kestrel will log on startup.

在生产中,HTTP通常通过端口80提供服务,而HTTPS通常通过端口443提供服务​​.如果没有另外指定,则为默认设置.

In production, HTTP is typically served over port 80, while HTTPS is served over port 443. These are the defaults if you don't specify otherwise.

另外,您可能要考虑启用 HTTPS重定向在您的 Configure 块中:

Separately, you might want to consider enabling HTTPS redirection in your Configure block:

app.UseHttpsRedirection();

这篇关于Asp.Net Core 2.0 HTTP->Kestrel上的HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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