• Published
  • 1 min

Exclude the FriendlyUrlRewriter in EPiServer

<p>The other day I made a Plug In to the editor that could insert a hyperlink to the MainBody of pages. I made this by extending the HyperLinkProperties.aspx, the PageBrowser.aspx, the PageExplorer.ascx and the HyperLinksProperties.js.</p>

I wanted this Plug In to return an URL on this format http://mysite.com/Templates/Pages/mypage.aspx?pageid=734&epslanguage=no&width=400&height=400. This because I wanted to use Smoothbox to pop the page information up in another window (Smoothbox is the Mootools conversion of Thickbox, a script running on JQuery. Read more about it and see great examples here, http://gueschla.com/labs/smoothbox/).

When I finally got this Plug In to return an URL to the editor, I came over another problem. When the page was rendered, I discovered that the EPiServer FriendlyUrlRewriter rewrote the URL so I could not use the pageid, width, and height parameter anymore. To prevent the FriendlyUrlRewriter to rewrite my URLs, I implemented this in the Global.asax.cs file and it worked like a charm:

protected void Application_Start(Object sender, EventArgs e)
{
FriendlyUrlRewriteProvider.UnTouchedPaths.Add("myUrlPath");
}

You can also hock on to a couple of events and do your own rewriting. The HtmlRewritingUrl happens before the URL is rewritten, and the HtmlRewroteUrl happens after the URL is rewritten. To hock on to these events, you can do this in your Global.asax.cs file:

protected void Application_Start(Object sender, EventArgs e)
{
HtmlRewriteToExternal.HtmlRewriteInit += HtmlRewriteInit;
}

void HtmlRewriteInit(object sender, HtmlRewriteEventArgs e)
{
FriendlyHtmlRewriteToExternal module = sender as FriendlyHtmlRewriteToExternal;
if (module != null)
{
module.HtmlRewritingUrl += HtmlRewritingUrl;
module.HtmlRewroteUrl += HtmlRewroteUrl;
}
}

void HtmlRewritingUrl(object sender, UrlRewriteEventArgs e)
{
// Happens before the URL is rewritten
}

void HtmlRewroteUrl(object sender, UrlRewriteEventArgs e)
{
// Happens after the URL is rewritten
}

For more great examples on custom URL Rewriting, take a look at these links:
Ted Nyberg: http://labs.episerver.com/en/Blogs/Ted-Nyberg/Dates/112276/7/Implementing-a-custom-URL-rewrite-provider-for-EPiServer/
EPiServer SDK: http://sdk.episerver.com/library/cms5/Developers%20Guide/Friendly%20URL.htm