admin管理员组

文章数量:1125333

I have a Blazor Hosted WebAssembly which means that I have three projects, the Client, the Server and the Shared. The inter-communication happens with web-apis.

On the Client, into index.html I have the following:

<base href="/app/" />

On the Client, into Clientn.csproj I have the following:

<StaticWebAssetBasePath>app</StaticWebAssetBasePath>

On the Server, into program.cs I have the following:

app.UseBlazorFrameworkFiles("/app");
app.UseStaticFiles();
app.UsePathBase("/app");
app.MapFallbackToFile("/app" + "/" + "index.html");

With those settings the application starts and loading but it fails to load two packages:

Blazored.Modal
Blazored.TextEditor

These two packages are trying to find resources into /app/_content but the resources are not there.

When the application is running without a subpath it works normally

Any ideas?

I have a Blazor Hosted WebAssembly which means that I have three projects, the Client, the Server and the Shared. The inter-communication happens with web-apis.

On the Client, into index.html I have the following:

<base href="/app/" />

On the Client, into Clientn.csproj I have the following:

<StaticWebAssetBasePath>app</StaticWebAssetBasePath>

On the Server, into program.cs I have the following:

app.UseBlazorFrameworkFiles("/app");
app.UseStaticFiles();
app.UsePathBase("/app");
app.MapFallbackToFile("/app" + "/" + "index.html");

With those settings the application starts and loading but it fails to load two packages:

Blazored.Modal
Blazored.TextEditor

These two packages are trying to find resources into /app/_content but the resources are not there.

When the application is running without a subpath it works normally

Any ideas?

Share Improve this question asked 2 days ago Stavros KoureasStavros Koureas 1,4721 gold badge18 silver badges45 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

app.UsePathBase("/app"); would consider https://localhost:port/app as the base path,you have to reach your static files with https:localhost:port/app/app/_content/Blazored.Modal/BlazoredModal.razor.js

A minimal sample that works well on myside:

Server project Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseWebAssemblyDebugging();
}
else
{
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();


app.UseStaticFiles();

app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/app"), app1 =>
{
    app1.UseBlazorFrameworkFiles("/app");    
    app1.UseRouting();
    app1.UseEndpoints(endpoints =>
    {
        endpoints.MapFallbackToFile("/app/{*path:nonfile}", "/app/index.html");
    });
});


app.Run();

.Client Project csproj:

 <StaticWebAssetBasePath>app</StaticWebAssetBasePath>

index.html:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>BlazoreModalApp</title>
    <base href="/app/" />
    <link href="css/app.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.snow.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.bubble.css" rel="stylesheet">
    <link href="BlazoreModalApp.Client.styles.css" rel="stylesheet">

    <!-- If you add any scoped CSS files, uncomment the following to load them
    <link href="BlazoreModalApp.Client.styles.css" rel="stylesheet" /> -->
</head>

<body>
    <div id="app">Loading...</div>

    <div id="blazor-error-ui">
        An unhandled error has occurred.
        <a href="" class="reload">Reload</a>
        <a class="dismiss">

本文标签: