2014-03-03 62 views
0

我有一個像網址:http://localhost.com/Dometic-Tou/french-with-flights-milano-10-12-may-2014.html如何獲得請求的URL與Request.Path.Substring

?我怎樣才能從URL這樣的文字:Domestic-Tou

我有鏈接,但我想要的只是Domestic-Tou從鏈接

我曾嘗試:

Request.Path.Substring(Request.Path.LastIndexOf("/") + 1); 

回答

1

不要使用Request.substring。它不會給你所需要的預期結果。而是使用這個。

string [] test = link.Split('/'); 

string required_subpart = test[3].ToString(); 

注意:這裏的索引是3。爲什麼因爲url包含http://。因此,如果您的網址中沒有http://,那麼索引應該是1.用您想要的任何部分替換爲網址中的部分。

讓我知道這是否適用於您,或者我有替代解決方案。

+0

我不能這樣做,我想第二個替代解決方案thx – neon

+0

我已經做了這個答案thx,我想知道第二個替代方案嗎?你可以告訴我嗎 ? – neon

+0

請投票答案,如果它的權利。我會盡快分享替代解決方案。您是否從Request.URL參數中獲取網址? – Josh