Abrahem haj hle Abrahem haj hle - 3 months ago 12
ASP.NET (C#) Question

asp.net get path page folder url

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

Answer

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.

Comments