• Publisert
  • 1 min

Friendly URL's everywhere

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

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/:


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.