【发布时间】:2021-08-18 18:49:03
【问题描述】:
我正在构建托管多个 Blazor WebAssembly 应用程序的 ASP.NET Core 应用程序。
我的服务器的Startup.cs:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Notes.Web.Server
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebAssemblyDebugging();
}
app.UseHttpsRedirection();
app.MapWhen(ctx => ctx.Request.Path.Equals("/client"), client =>
{
client.Use((ctx, nxt) =>
{
ctx.Request.Path = "/client" + ctx.Request.Path;
return nxt();
});
client.UseBlazorFrameworkFiles("/client");
client.UseStaticFiles();
client.UseRouting();
client.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("/client/{*path:nonfile}", "client/index.html");
});
});
}
}
}
当我尝试访问/client 地址时,页面加载成功,但由于找不到脚本_framework/blazor.webassembly.js,应用程序无法加载。
在客户的index.html 我有<base href="/client/" />
如您所见,所有配置都与Microsoft documentation中的相同
但它不起作用。请帮我。谢谢!
【问题讨论】:
-
调试 (F12) 请求,失败请求中的 URL 是什么?
标签: c# asp.net-core blazor blazor-webassembly