Blazor WASM get current URL in program.cs

Viewed 32

Is there a way to get the URL from program.cs file? I've seen an option with @inject NavigationManager MyNavigationManager but it is for components.

1 Answers

So is this Blazor server-side or client-side? If it's client-side you can use the IWebAssemblyHostEnvironment to get the url. You can try this:

private static void ConfigureServices(IServiceCollection services, IWebAssemblyHostEnvironment hostEnvironment)
{
    var baseAddress = hostEnvironment.BaseAddress;
}
Related