Go to content

Go to employees

Go to search

Friendly URL's outside normal page context

Some times you want to render pages or controls outside the regular EPiServer page context. In my case, I was rendering an .ascx-file in an IHttpHandler and outputting it asynchronously through Javascript - which caused some trouble with friendly URLs.

Arve Systad
 

When you do this, the configured URLRewriteProvider doesn't seem to kick in like you're used to. Links to EPiServer-pages are output simply as /Path/To/Your/Template.aspx?id=1337. It works, but exposing your application's inner workings to the browser isnt' really clean.

The solution, however, is simpler than I first thought. At least in my case, when rendering an .ascx from a handler. Simply add the following line somewhere before Request.End() is called, and your links will be as /pretty/as/they/should/be/:

UrlRewriteProvider.Module.HtmlAddRewriteToExternalFilter(HttpContext.Current.ApplicationInstance);

It's all in the details.

Update: This uses default EPiServer rewrite functionality. In my case, I also needed to hide a link in an input type="hidden", which was not rewritten. So it seems that ConvertToExternal-like methods still have a purpose.


Comments:

Post a comment