I am trying to figure out how to access the current absolute Uri -- i.e. the absolute url of the view that is currently being rendered -- from a user class in .
You may use the GetDisplayUrl
extension method.
var url = httpContextAccessor.HttpContext?.Request?.GetDisplayUrl();
Assuming httpContextAccessor
is an object of IHttpContextAccessor
which was injected via DI.
This extension method is defined in Microsoft.AspNetCore.Http.Extensions
namespace. So you need to have a using statement to include it in your file.
using Microsoft.AspNetCore.Http.Extensions;