我有这样的网址:
http://www.example.com/Catalog/Category/Detail
http://www.example.com/Catalog/Products/12
现在,我想提取/Catalog/Category/Detail
和/Catalog/Products/12
部分,以便我可以附加一些其他基本网址。我怎么能这么容易地做到这一点?
答案 0 :(得分:1)
使用Uri
class,并使用Uri.LocalPath
属性,如:
Uri uri = new Uri("http://www.example.com/Catalog/Category/Detail");
Console.WriteLine(uri.LocalPath); // /Catalog/Category/Detail
答案 1 :(得分:0)
var segments = new Uri("http://www.example.com/Catalog/Category/Detail").Segments;
这将返回
/
Catalog/
Category/
Detail