We have a class System.Uri which takes absolute/full url as a parameter and gives the relative url.
using System;
private static string GetRelativeUrl(string fullUrl)
{
try
{
Uri uri = new Uri(fullUrl);//fullUrl is absoluteUrl
string relativeUrl = uri.AbsolutePath;//The Uri property AbsolutePath gives the relativeUrl
return relativeUrl;
}
catch (Exception ex)
{
return fullUrl;
//throw ex;
}
}
No comments:
Post a Comment