C# 如何在ASP.NET Core中仅对特定URL使用SPA()
我想配置我的ASP.NET核心应用程序,使其仅显示特定URL的SPA应用程序。假设我有两个租户:租户1和租户2,我希望在用户请求时显示SPA应用程序: 或 我试着这样做:C# 如何在ASP.NET Core中仅对特定URL使用SPA(),c#,.net,asp.net-core,C#,.net,Asp.net Core,我想配置我的ASP.NET核心应用程序,使其仅显示特定URL的SPA应用程序。假设我有两个租户:租户1和租户2,我希望在用户请求时显示SPA应用程序: 或 我试着这样做: app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
app.MapWhen(context =>
{
var uriTenantId = new Uri(context.Request.GetDisplayUrl()).Segments.FirstOrDefault(x => x != "/");
var tenantId = context.GetTenant()?.Id;
return uriTenantId != null && uriTenantId == tenantId;
}, builder =>
{
builder.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
});
它的工作方式与显示Tenant1和Tenant2 SPA的方式相同,但对静态文件的请求返回404。有没有关于如何正确配置的建议?您可以在Angular(SPA)内部处理此问题!您可以在Angular(SPA)内部处理此问题!