[英]Asp.Net Core 2.0 HTTP -> HTTPS on Kestrel
I am learning Web-Based Programming and currently chose to work on Asp.Net Core 2.0. 我正在学习基于Web的编程,目前选择在Asp.Net Core 2.0上工作。 I had successfully created a Web App with 2 layers of Controllers Home & API.
我已经成功创建了一个包含2层Controllers Home&API的Web应用程序。 The Home Controller interacts directly with my Views while the API controller is called using GetAsync, PostAsync, PutAsync, etc. from my Home controller.
当从Home控制器使用GetAsync,PostAsync,PutAsync等调用API控制器时,Home控制器与我的视图直接交互。 Recent I decided to move this app into HTTPS.
最近,我决定将此应用程序移至HTTPS。 Learned about self-signed certificates and had successfully gotten it to run except my API becomes inaccessible.
了解了自签名证书,并成功运行了该证书,但无法访问我的API。
With SSL switched off, I could still call my API with Postman. 关闭SSL后,我仍然可以使用Postman调用我的API。
I used to call my API using this URI: http://localhost:5667/api/WebApi . 我以前使用以下URI来调用我的API: http:// localhost:5667 / api / WebApi 。
var response = client.GetAsync(“SomeApi”)
response.Wait();
Now I tried using URI: https://localhost:5667/api/WebApi but breaks at response.Wait().
现在,我尝试使用URI: https:// localhost:5667 / api / WebApi,但在
response.Wait().
处中断response.Wait().
Any advice, please. 请提供任何建议。 Thanks in advance
提前致谢
As requested: here's a portion of my Startup.cs 根据要求:这是我的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 and HTTPS cannot be served over the same port. HTTP和HTTPS不能在同一端口上提供服务。 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端点在5667上,那么您的HTTPS端点可能在5668上-尽管您可以在Kestrel将在启动时登录的信息中检查自己的端口号。
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. 在生产中,HTTP通常通过端口80提供服务,而HTTPS通常通过端口443提供服务。如果没有另外指定,则为默认设置。
Separately, you might want to consider enabling HTTPS redirection in your Configure
block: 另外,您可能要考虑在
Configure
块中启用HTTPS重定向 :
app.UseHttpsRedirection();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.