Posted By

housecor on 11/01/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Tyster
tonicglop


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


 / Published in: C#
 

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

  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  

You need to login to post a comment.