Get Current URL and Segments. Also, get host or path.


/ Published in: C#
Save to your folder(s)

Segments is a zero based array that starts with the first segment.


Copy this code and paste it in your HTML
  1. Uri address = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
  2. if (address.Segments[0] == "Admin") //do something...
  3.  
  4. string path = HttpContext.Current.Request.Url.AbsolutePath;
  5. // /TESTERS/Default6.aspx
  6.  
  7. string host = HttpContext.Current.Request.Url.Host;
  8. // localhost

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.