The method of getting the URL of the current page in asp. net of recommendation

  • 2021-08-21 20:08:54
  • OfStack

There are two ways to get Url, either in the background or through the previous js, as follows:

1. Get the URL of the current page through C #

string url = Request. Url. AbsoluteUri; //Outcome: https://www.ofstack.com/web/index.aspx
string host = Request. Url. Host; //Results: www. ofstack. com
string rawUrl = Request. RawUrl; //Results:/web/index. aspx
string localPath = Request. Url. LocalPath; //Results:/web/index. aspx

2. Obtain the URL of the current page through Javascript

var url = document. URL; //Results: https://www.ofstack.com/web/index. aspx
var href = document. location. href; //Results: https://www.ofstack.com/web/index.aspx
var host = location. hostname; //Results: www. ofstack. com


Related articles: