ASP.Net MVC 核心:预渲染构建过程未在 50 秒的超时期限内完成
ASP.Net MVC Core: The prerendering build process did not complete within the timeout period of 50 seconds
我有 ASP.Net MVC 核心 (2.1.0),带有 SPA 预渲染。
我的 JWT 令牌中间件出现超时,在 "await next()".
行
当我将 @angular/cli 更新到最新版本 (v6.0.8) 时,我开始遇到错误,其中还添加了 @angular-devkit/build-angular (v0.6.8)。
当 运行 "ng build" 时我没有收到任何错误。
public static class JwtTokenMiddleware
{
public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema = JwtBearerDefaults.AuthenticationScheme)
{
return app.Use(async (ctx, next) =>
{
if (ctx.User.Identity?.IsAuthenticated != true)
{
var result = await ctx.AuthenticateAsync(schema);
if (result.Succeeded && result.Principal != null)
{
ctx.User = result.Principal;
}
}
await next();
});
}
}
堆栈跟踪:
System.TimeoutException: The prerendering build process
did not complete within the timeout period of 50 seconds. Check the
log output for error information. at
Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout(Task
task, TimeSpan timeoutDelay, String message) at
Microsoft.AspNetCore.Builder.SpaPrerenderingExtensions.<>c__DisplayClass0_0.<b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext
httpContext) at
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext
context) at
MyProject.JwtTokenMiddleware.<>c__DisplayClass0_0.<b__0>d.MoveNext()
in
/MyProject/UseJwtTokenMiddleware.cs:line
23
--- End of stack trace from previous location where exception was thrown --- at
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext
context)
更新:
angular-cli 升级替换了一些设置。原始 .angular-cli.json 文件具有服务器端呈现文件夹的设置。升级重写的新 angular.json 文件消失了。这就是 ASP.Net 找不到它的原因。我现在必须将 SSR 设置放回 angular.json 文件中。
更新 2:
https://angular.io/guide/universal#angular-cli-configuration 的文档概述了要放入 angular.json 的内容。
在 startup.cs
文件中,转到代码的 IsDevelopment
部分并添加以下行:
if (env.IsDevelopment())
{
//Time limit extended
spa.Options.StartupTimeout = new TimeSpan(days: 0, hours: 0, minutes: 1, seconds: 30);
//Time limit extended
spa.UseAngularCliServer(npmScript: "start");
}
确保 SSL 标记在 angular.json 中不是真的,如果你已经添加了它。
我有 ASP.Net MVC 核心 (2.1.0),带有 SPA 预渲染。
我的 JWT 令牌中间件出现超时,在 "await next()".
行当我将 @angular/cli 更新到最新版本 (v6.0.8) 时,我开始遇到错误,其中还添加了 @angular-devkit/build-angular (v0.6.8)。
当 运行 "ng build" 时我没有收到任何错误。
public static class JwtTokenMiddleware
{
public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema = JwtBearerDefaults.AuthenticationScheme)
{
return app.Use(async (ctx, next) =>
{
if (ctx.User.Identity?.IsAuthenticated != true)
{
var result = await ctx.AuthenticateAsync(schema);
if (result.Succeeded && result.Principal != null)
{
ctx.User = result.Principal;
}
}
await next();
});
}
}
堆栈跟踪:
System.TimeoutException: The prerendering build process did not complete within the timeout period of 50 seconds. Check the log output for error information. at Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout(Task task, TimeSpan timeoutDelay, String message) at Microsoft.AspNetCore.Builder.SpaPrerenderingExtensions.<>c__DisplayClass0_0.<b__1>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at MyProject.JwtTokenMiddleware.<>c__DisplayClass0_0.<b__0>d.MoveNext() in /MyProject/UseJwtTokenMiddleware.cs:line 23 --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
更新:
angular-cli 升级替换了一些设置。原始 .angular-cli.json 文件具有服务器端呈现文件夹的设置。升级重写的新 angular.json 文件消失了。这就是 ASP.Net 找不到它的原因。我现在必须将 SSR 设置放回 angular.json 文件中。
更新 2:
https://angular.io/guide/universal#angular-cli-configuration 的文档概述了要放入 angular.json 的内容。
在 startup.cs
文件中,转到代码的 IsDevelopment
部分并添加以下行:
if (env.IsDevelopment())
{
//Time limit extended
spa.Options.StartupTimeout = new TimeSpan(days: 0, hours: 0, minutes: 1, seconds: 30);
//Time limit extended
spa.UseAngularCliServer(npmScript: "start");
}
确保 SSL 标记在 angular.json 中不是真的,如果你已经添加了它。