开发者

How to get absolute url without root?

开发者 https://www.devze.com 2023-04-11 05:44 出处:网络
I have this root: http://localhost/foldername/about I 开发者_StackOverflow社区would like to get only the /about part.

I have this root: http://localhost/foldername/about

I 开发者_StackOverflow社区would like to get only the /about part.

How can I do this?


Use Uri.Segments Property

The Segments property returns an array of strings containing the "segments" (substrings) that form the URI's absolute path. The first segment is obtained by parsing the absolute path from its first character until you reach a slash (/) or the end of the path. Each additional segment begins at the first character after the preceding segment, and terminates with the next slash or the end of the path. (A URI's absolute path contains everything after the host and port and before the query and fragment.)

Uri uriAddress1 = new Uri("http://localhost/foldername/about");
Console.WriteLine("The parts are {0}, {1}, {2}", uriAddress1.Segments[0], 
                  uriAddress1.Segments[1], uriAddress1.Segments[2]);

See more about Uri Class MSDN


This should be of help to you:

http://www.west-wind.com/weblog/posts/2009/Dec/21/Making-Sense-of-ASPNET-Paths

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号