0
Follow
0
View

How to Get Environment in Blazor WebAssembly in Case Of Prerendering

duron571 注册会员
2023-01-25 04:35

I could handle both of the scenario in the following way.It needs to add Microsoft.AspNetCore.Hosting Nuget Package to Client side code which increased download size from 9.33 to 9.6 MB.

@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
@using Microsoft.AspNetCore.Hosting
@inject IServiceProvider sp
@{
    bool isProduction;
}
@if (sp.GetService<Environment>() is not null)
{
    var env = sp.GetRequiredService();
    isProduction = env.IsProduction();
}
else
{
    var env = sp.GetRequiredService();
    isProduction = env.IsProduction();
}

About the Author

Question Info

Publish Time
2023-01-25 04:35
Update Time
2023-01-25 04:35