Blazor Server - static files don't link in non-DEV environments

自古美人都是妖i 提交于 2019-12-06 04:38:46

Consuming static assets from a Razor Class Library works out of the box when the application gets published. You just have to include the static content via <link href="..." /> as you did.

However, when running the app from the build output (dotnet run) or via F5 in Visual Studio you have to ensure that the StaticWebAsset feature is enabled for the given environment.

It is enabled by default for the development environment only. You can turn on the feature unconditionally by ensuring you called UseStaticFiles and calling UseStaticWebAssets in the Program.CreateHostBuilder.

So, ensure that you consuming app has :

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...

    app.UseStaticFiles();

    ...
}

and in your Program.cs you should have

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStaticWebAssets();
            webBuilder.UseStartup<Startup>();
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!