I want to extract the name of a particular directory of a URL and save it to a string from the server-side in ASP.NET C#.
For example, lets say I have a URL that looks like this:
http://localhost:1096/directory1/directory2/default.aspx
How would I get the value of directory1 from the URL and save it to a string variable?
Thanks in advance.

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 12, 2013, 3:21 AM EDT
you can get current page url using below code.
string CurrentURL = System.Web.HttpContext.Current.Request.Url;
or refer to this link
http://forums.asp.net/t/1383898.aspx
Sayed Hassan17 reputationPosted Sep 12, 2013, 3:54 AM EDT
http://msdn.microsoft.com/en-us/library/system.uri.segments[^]