How to get the current page URL in asp.net using the code behind the technique?

I want to get Url pages, for example abc.aspx. how can i get this using the code behind the technique. Any idea.?

+6
source share
4 answers

Details, later you can use the Operations line for advanced manipulation:

string url = HttpContext.Current.Request.Url.AbsoluteUri; // http://localhost:1302/TESTERS/Default6.aspx string path = HttpContext.Current.Request.Url.AbsolutePath; // /TESTERS/Default6.aspx string host = HttpContext.Current.Request.Url.Host; // localhost 

How to get url of current page in C #

+16
source

Use Request.RawUrl :

Gets the raw URL of the current request.

+5
source

Request.RawUrl property gives you the full URL of your current page.

+3
source

You can set the current page URL as a canonical tag using below. Here we set the exact URL of the page with a dynamic host name.

for example: if you want to install the canonical tag: http://www.TestWorld.co.uk/about

In the code below, the host name will be dynamic, since http://www.TestWorld.co.uk/ and Request.RawUrl will give the result, in the end we get a purely dynamic canonical url. Note. Here the canonical tag will be dynamically created on the html page, you do not need to create it manually.

 HtmlLink canonical = new HtmlLink(); var uri = Request.Url; string hostName = uri.GetLeftPart(UriPartial.Authority); canonical.Href = hostName + Request.RawUrl.ToString(); canonical.Attributes["rel"] = "canonical"; Page.Header.Controls.Add(canonical); 
0
source

Source: https://habr.com/ru/post/907633/


All Articles