Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get FULL URL in ASP.NET Core Razor Pages?

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?

like image 973
Ali EXE Avatar asked Nov 25 '25 11:11

Ali EXE


2 Answers

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();
like image 110
haldo Avatar answered Nov 27 '25 00:11

haldo


You can do it by this way. In .net core

@using Microsoft.AspNetCore.Http
@{
    string url = Context.Request.Path;
}
like image 28
Matías Alejandro Novillo Avatar answered Nov 27 '25 00:11

Matías Alejandro Novillo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!