I want to get the full URL, not just the Path, not just the Query, and not RouteValues.
The entire URL as it has come in the raw form.
How can I do that in ASP.NET Core Razor Pages?
You can use the UriHelper extension methods GetDisplayUrl() or GetEncodedUrl() to get the full URL from the request.
GetDisplayUrl()
Returns the combined components of the request URL in a fully un-escaped form (except for the QueryString) suitable only for display. This format should not be used in HTTP headers or other HTTP operations.
GetEncodedUrl()
Returns the combined components of the request URL in a fully escaped form suitable for use in HTTP headers and other HTTP operations.
Usage:
using Microsoft.AspNetCore.Http.Extensions;
...
string url = HttpContext.Request.GetDisplayUrl();
// or
string url = HttpContext.Request.GetEncodedUrl();
You can do it by this way. In .net core
@using Microsoft.AspNetCore.Http
@{
string url = Context.Request.Path;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With