簡體   English   中英

如何獲得沒有root的絕對URL?

[英]How to get absolute url without root?

我有這個根: http:// localhost / foldername / about

我只想獲得/about部分。

我怎樣才能做到這一點?

使用Uri.Segments屬性

Segments屬性返回一個字符串數組,其中包含構成URI絕對路徑的“段”(子字符串)。 通過解析從第一個字符到到達斜線(/)或路徑末尾的絕對路徑來獲得第一段。 每個其他段均從前一個段之后的第一個字符開始,並以下一個斜杠或路徑的結尾終止。 (URI的絕對路徑包含主機和端口之后,查詢和片段之前的所有內容。)

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]);

查看有關Uri類MSDN的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM