#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

How to use UriHelper or NavigationManager in .NET Core 3.0 & Blazor?

koskila
Reading Time 2 min
Word Count 282 words
Comments 2 comments
Rating n/a (0 votes)
View

Just a quick piece of documentation, as this piece of code, has changed in different versions of .NET Core 3.0 so far a few times. Need to have things like this written down somewhere!

UriHelper / NavigationManager with .NET Core 3.0

Both of these helper libraries do essentially the same thing: navigate/browse/redirect the user to a different address, component, page or view in or by your web app. What you normally use this library for is exactly the same in all versions I've worked with, anyway, and that goes as follows:

// to redirect the user, do something like this:
uriHelper.NavigateTo("/yourPage"); // to do a dynamic refresh with injected UriHelper

navMan.NavigateTo("/yourPage", true); // to also force page refresh instead of a dynamic load with injected NavigationManager

See below for how to inject these dependencies into your pages and views!

< .NET Core 3.0 preview 7

Before preview 7, the UriHelper would be available from namespace Microsoft.AspNetCore.Blazor.Services. I suppose that made sense originally, if the services was to be used by just Blazor? This is how to use it:

@inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper

.NET Core 3.0 preview 7

In .NET Core 3.0 preview 7, the UriHelper library's (used in Blazor) namespace and usage has changed a bit.

Instead, it is now out of the Blazor namespace and in the Components.Services namespace.

@inject Microsoft.AspNetCore.Components.Services.IUriHelper UriHelper

.NET Core 3.0 preview 8

Yes, it's changed again. Now it's out of the "Services" namespace.

@inject Microsoft.AspNetCore.Components.IUriHelper UriHelper

.NET Core 3.0 preview 9 +

Okay, so I recall this has been the same in preview 9 and the GA version.

@inject NavigationManager NavigationManager

Yeah ok, so that's that. Short and sweet for a change :)

References

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Blazor123
2019-12-24 03:41:14)
Now it's in Microsoft.AspNetCore.Http.Extensions
2019-12-26 00:29:00
Hey mate, Thanks for your comment. Which .NET Core version are you using? Couldn't see any mention of this in the release notes, and it seems to be under AspNetCore.Components in 3.1 at least... https://tiedostot.koskila.net/public/devenv_2019-12-26_00-26-01.jpg
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-21T07:25:13Z