To handle a specific use case I had to capture the current URL in ASP.NET Core. I found a lot of outdated answers on the Internet so here is the correct way in case I forget(which I certainly will do):
In the Microsoft.AspNetCore.Http.Extensions assembly a static UriHelper class exists that allows you to get the URL from an HttpRequest object:
var url= UriHelper.GetEncodedUrl(httpContext.Request);
This GetEncodedUrl() method can also be used as an extension method directly on the HttpRequest(don’t forget to import the namespace):
var url= httpContext.Request.GetEncodedUrl();
Maybe it helps you too!