question

panpawel-3022 avatar image
0 Votes"
panpawel-3022 asked panpawel-3022 commented

ASP.NET Core - static web assests from nuget package (Radzen.Blazor, Microsoft Identity) load only when environment is Development, not when Staging.

I have a ASP.NET Core Blazor Server with Identity.
When I run in the Development environment ("ASPNETCORE_ENVIRONMENT": "Development"), everything works as expected. Specifically, the static web assest such as css and js files are loaded. Example: "~/Identity/css/site.css", "~/Identity/lib/jquery-validation/dist/jquery.validate.min.js".
But when I change the environment to Staging, all the files in "~/Identity/..." path are not found, returning 404 error. And it is not just my project. I created a brand new scaffolded Blazor app with Identity, and it behaves exactly the same. It appears Staging somehow affects sdk to not include embeded resources from .nuget.

Any ideas why? And how to fix it?

dotnet-aspnet-core-blazor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ZhiLv-MSFT avatar image
1 Vote"
ZhiLv-MSFT answered panpawel-3022 commented

Hi @panpawel-3022,

The static web assets are enabled by default in the Development environment. To support assets in other environments when running from build output, call UseStaticWebAssets on the host builder in Program.cs:

     public static IHostBuilder CreateHostBuilder(string[] args) =>
         Host.CreateDefaultBuilder(args)
             .ConfigureWebHostDefaults(webBuilder =>
             {
                 webBuilder.UseStaticWebAssets(); 
                 webBuilder.UseStartup<Startup>();
             });

After that, the result as below:

119291-image.png

Reference: Consume content from a referenced RCL


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best Regards,
Dillion



image.png (81.7 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Many thanks! I googled it for 2 days and could not find the answer.

0 Votes 0 ·