c# - .NET core 3.1 - Angular 9 - Angular CLI 进程没有在 0 秒的超时时间内开始监听请求

标签 c# angular asp.net-core

[ 小心这个问题已经被问过了,但没有任何建议似乎有效,而且在我的情况下超时是 0 ]

问题:

我的计算机上无法运行 .NET Core/angular 应用程序

它可以在家里工作(Win 7,VS 2019 社区),但是 不在我的工作电脑上(Win10,VS 2019 pro)

Chrome/FFox 不断加载索引页面,然后我超时

错误:

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.

System.TimeoutException: The Angular CLI process did not start listening for requests within the timeout period of 0 seconds. Check the log output for error information.
   at Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout[T](Task`1 task, TimeSpan timeoutDelay, String message)
   at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task`1 baseUriTask, CancellationToken applicationStoppingToken, Boolean proxy404s)
   at Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

预期行为:

angular 应用程序应显示在浏览器中

我试过的:

我更新了很多次VS

我升级了 angular 两次(从 8.0 -> 8.2 -> 9.1.9)
ng update @angular/core@8 @angular/cli@8
ng update @angular/core@9 @angular/cli@9

我尝试添加超时
spa.Options.StartupTimeout = new TimeSpan(0, 0, 80);
spa.UseAngularCliServer(npmScript: "start");

我尝试替换 package.json 中的 start 命令
"start": "echo Starting... && ng serve",

我在 angular.json 中添加了构建进度以查看应用程序何时可用
"browserTarget": "WebApplication1:build",
"progress": true

我看到 IISExpress 正在监听端口
C:\WINDOWS\system32>netstat -afo | grep 22710
  TCP    0.0.0.0:22710          ########################.net:0  LISTENING       4

我试图在 launchSettings.json 中将端口更改为另一个
"applicationUrl": "http://localhost:8081",

我也试过这样做,但端口被一些似乎无法访问的随机端口覆盖
ng serve --port 8081

我可以在命令行上运行 angular 应用程序
  • 使用 ng服务 , angular 应用程序出现但没有后端服务
  • 使用 dotnet 运行 ,我遇到了同样的超时问题

  • 总体:

    .NET 核心框架似乎无法以某种方式联系 angular cli

    知道我可以检查或更改什么来完成这项工作吗?

    感谢您花时间在这件事上

    最佳答案

    增加启动超时
    在启动.cs

     app.UseSpa(spa =>
        {
            
            spa.Options.SourcePath = "ClientApp";
            spa.Options.StartupTimeout = new TimeSpan(0, 5, 0);
            if (env.IsDevelopment())
            {
                
                spa.UseAngularCliServer(npmScript: "start");
            }
        });
    
    在 angular.json 上
       "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "xxxx:build",
            "progress": true
          },
    
    为我工作。

    关于c# - .NET core 3.1 - Angular 9 - Angular CLI 进程没有在 0 秒的超时时间内开始监听请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62039447/

    相关文章:

    java - Angular 2/Spring Security CSRF 实现问题

    angular - 是否可以像使用模块一样在 Angular 2 中延迟加载组件?

    c# - 如何在 EF Core 2.1.0 中设置管理员用户?

    c# - Autofac - 在运行时解析 IEnumerable 通用接口(interface)

    c# - 如何在 WPF 图像中显示位图

    C# 将文件读入二维数组

    json - MEAN Stack 应用程序 - 发送后无法设置 header

    c# - 带有 ASP.NET Core 的 SignalR 不使用 websockets 但使用长轮询

    asp.net-core - .net core 2.2如何登录Program.Main?

    c# - 以编程方式创建文档 Kentico 9