Abrahem haj hle Abrahem haj hle - 1 year ago 68
ASP.NET (C#) Question

asp.net get path page folder url

I have the following url:


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?


The full path without the

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download