Created
April 3, 2012 13:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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