Reputation: 57
I have the following url:
localhost:1088/Web_Market/A/Sport.aspx
It is stored in a string, as below:
string str = "localhost:1088/Web_Market/A/Sport.aspx"
How can I edit the string so it returns the following?
localhost:1088/Web_Market/A/
The full path without the Sport.aspx
Upvotes: 2
Views: 639
Reputation: 499
Use below code
Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf('/') + 1);
This will find substring until the last occurance of "/", which will fetch the URL upto what you needed.
Upvotes: 3