我尝试在一个ASP.NET Core 7应用程序下运行多个本地化的Angular应用程序。
目前,我使用默认的ASP.NET Core Web应用程序模板,并在Angular编译时使用--localize
开关。这将导致两个Angular文件夹:
ClientApp/dist/en
ClientApp/dist/de
我尝试像这样配置映射:
...
app.Map("/de",
userApp =>
{
userApp.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp/dist/de";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "dist", "de"))
};
// if (app.Environment.IsDevelopment())
// spa.UseProxyToSpaDevelopmentServer("http://localhost:4000");
});
});
app.Map("/en",
userApp =>
{
userApp.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp/dist/en";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "dist", "en"))
};
});
});
app.MapFallbackToFile("index.html");
app.Run();
但是当我请求
localhost:80/de
时,我收到一个错误:
失败:Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
在执行请求时发生了一个未处理的异常。
System.InvalidOperationException:请求在没有执行端点的情况下到达管道的末尾:'Fallback {*path:nonfile}'。如果使用路由,请使用'IApplicationBuilder.UseEndpoints(...)'注册EndpointMiddleware。
at Microsoft.AspNetCore.Builder.ApplicationBuilder.<>c.b__18_0(HttpContext context)
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.b__1(HttpContext context, RequestDelegate next)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.b__0(HttpContext context, RequestDelegate next)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
这个解决方案适用于ASP.NET Core 5,但大多数我能找到的示例都比较旧。
spa.Options.DefaultPage = new PathString("/index.html")
- kemsky