加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – 为什么.net core 2.1 SPA有3个不同的端口?

发布时间:2020-12-16 03:53:02 所属栏目:asp.Net 来源:网络整理
导读:我正在学习dotnet核心2.1 SPA,当我运行带有dotnet运行的donet核心2.1 SPA Angular时,我注意到有3个不同的端口: https:localhost:5001 http:localhost:5000 http:localhost:34941 当我使用第二个网址时,它只是自动重定向到第一个网址,我收到了安全错误
我正在学习dotnet核心2.1 SPA,当我运行带有dotnet运行的donet核心2.1 SPA Angular时,我注意到有3个不同的端口:

> https:localhost:5001
> http:localhost:5000
> http:localhost:34941

当我使用第二个网址时,它只是自动重定向到第一个网址,我收到了安全错误.
对于第3个网址,它可以工作.我认为因为它是针对客户端的,第一和第二个URL将用于带有身份验证的API调用?
在现场环境中会发生什么?

Result from running <code>dotnet run</code>

Program.cs文件中的配置

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

解决方法

5000和5001:Kestrel HTTP和HTTPS默认值

5000用于HTTP,5001用于HTTPS.这些是defaults in the ASP.NET Core Kestrel Server. 5000由于你的Startup类中的app.UseHttpsRedirection()而重定向到5001.

34941:NG Live Development Server的任何可用端口

这是Microsoft.AspNetCore.SpaServices用于启动NG Live Development Server的任意可用端口. Startup类中的spa.UseAngularCliServer(npmScript:“start”)方法从package.json文件中调用启动脚本,如下所示:

ng serve --extract-css "--port" "50415"`

它传递的端口是SpaServices找到的任何当前available port.

也可以看看

> https://github.com/aspnet/JavaScriptServices
> https://github.com/aspnet/KestrelHttpServer

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读