Skip to content

Instantly share code, notes, and snippets.

@timabell
Created April 3, 2012 13:27
Show Gist options
  • Save timabell/2291964 to your computer and use it in GitHub Desktop.
Save timabell/2291964 to your computer and use it in GitHub Desktop.
episerver url rewriting, put this in a template page's code-behind .cs
protected string ResourcePath
{
get
{
return
_pageFilesUrl ?? (_pageFilesUrl = ResolveUrl(String.Format("~/PageFiles/{0}/", FolderId)));
}
}
private int FolderId
{
get
{
return (int)GetPage(CurrentPage.ParentLink)["PageFolderID"]; // todo: cope with html files in subdirectories when looking up folder
}
}
private string ReplaceUris(string html)
{
// get any old property to gain access to instance method ReplaceHtmlLinks()
var propertyData = CurrentPage.Property[0];
// translate relative links to absolute links that match the static file storage in PageFiles
return html == null ? String.Empty : propertyData.ReplaceHtmlLinks(html, TranslateUri);
}
private string TranslateUri(string url)
{
// alter any relative urls found
return Uri.IsWellFormedUriString(url, UriKind.Relative) && !url.StartsWith("/")
? ResourcePath + url
: url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment