As stated in the document:
HttpContext can be used as a cascading parameter only in statically-rendered root components for general tasks, such as inspecting and modifying headers or other properties in the App component (Components/App.razor). The value is always null for interactive rendering.
You could get the absolute URL with NavigationManager,for example:
public class MyService
{
public MyService(NavigationManager navigationManager)
{
_navigationManager = navigationManager;
}
private readonly NavigationManager _navigationManager;
public string GetUri()
{
var currentUri = _navigationManager.Uri;
return currentUri;
}
}
Result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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,
Ruikai Feng