Relative to absolute paths in HTML
One of the possible ways to resolve this task is the use the HtmlAgilityPack library.
Some example (fix links):
WebClient client = new WebClient();
byte[] requestHTML = client.DownloadData(sourceUrl);
string sourceHTML = new UTF8Encoding().GetString(requestHTML);
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(sourceHTML);
foreach (HtmlNode link in htmlDoc.DocumentNode.SelectNodes("//a[@href]"))
{
if (!string.IsNullOrEmpty(link.Attributes["href"].Value))
{
HtmlAttribute att = link.Attributes["href"];
att.Value = this.AbsoluteUrlByRelative(att.Value);
}
}
if the request comes in from your site (same domain links) then you can use this:
new Uri(Request.Uri, "/img/welcome.png").ToString();
If you're in a non-web app, or you want to hardcode the domain name:
new Uri("http://www.mysite.com", "/img/welcome.png").ToString();