How to get current url

Possible duplicate:
How to get url of current page in C #

If I say http://myweb/folder/obtain.aspx?thevalue=3 on the page, how can I determine if the URL contains obtain.aspx?thevalue in C # ?. I just need to check if the user has landed on this page.

PS: I think I really don't need to check ?thevalue , but just obtain.aspx

+6
source share
6 answers

Try the following:

 //gets the current url string currentUrl = Request.Url.AbsoluteUri; //check the url to see if it contains your value if (currentUrl.ToLower().Contains("obtain.aspx?thevalue")) //do something 
+9
source

Request.Url should contain everything you need. In your case, you can use something like

 if( Request.Url.PathAndQuery.IndexOf("obtain.aspx") >= 0 )... 
+1
source

I recommend using Request.Url . To get the exact file name, you can try also using System.IO.Path

 var aspxFile = System.IO.Path.GetFileName(Request.Url.LocalPath); var landed = aspxFile.Equals("obtain.aspx", StringComparison.InvariantCultureIgnoreCase); if(landed) { // your code } 
+1
source

This will give you the exact file name (get.aspx) Request.Url.Segments [1]

+1
source

Request.Url will return the exact Uri requested by the user.

If you want to specifically set for thevalue , you are probably better off looking for this in Request.QueryString

0
source

it's ugly but you try to try

 if (HttpContext.Current.HttpRequest.Url.AbsolutePath.Contains("/obtain.aspx")) // then do something 
0
source

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