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

panpawel 1 Reputation point
2021-07-21T16:40:30.923+00:00

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?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,578 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,336 Reputation points Microsoft Vendor
    2021-07-30T05:22:11.073+00:00

    Hi @panpawel ,

    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

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.