Try our conversational search powered by Generative AI!

Url rewriting


hi guys, currently, internal page links coming from objects such as url or content links are not being rewritten to friendly urls by episerver on page render.  What things do I need to check are set for this to occur please?  

Dec 07, 2014 15:14

Hey Adam,

Could you inform us on what you are using for a framework.  MVC, Webforms?

You can use the url resolver if you need too.  UrlResolver.Current.GetUrl(contentLink) or mvc @Url.ContentUrl(contnetlink or url).

Dec 07, 2014 19:52

Hi Joshua, we are using mvc with razor.

Dec 08, 2014 10:00

Thanks Adam,

Can you post a code sample that is not being re-written.  I supect that either the routescollection is not being registered or operator error.  Could do you use the favor of posting a sample code that is not working as you intend it too.

Dec 08, 2014 15:31

Hi Joshua, sure.

Using an episerver url field:

public virtual Url TargetUrl { get; set; }


<a href="@Model.TargetUrl" class="button button--black">Read more</a>



Using an episerver typed page field:

public T CurrentPage { get; private set; }  (T being the typed page data).


<a href="@(((PageData)Model.CurrentPage).LinkURL)" class="news-articles__cta">Read more</a>



In the mean time ive been using the UrlResolver.Current.GetUrl(contentLink) or mvc @Url.ContentUrl(contnetlink or url) you suggested above, which works on both.

Dec 08, 2014 16:03

do this

<a href="@Url.CotnentUrl(Model.TargetUrl)" class="button button--black">Read More</a> and for the second one.  Do <a href="@Url.ContentUrl(Model.CurrentPage.ContentLink> class="news-articles__cta">Read More</a>

let me know if that works for you.

Dec 08, 2014 16:20

hi Josh, as i said at the bottom, I am already doing that as per your original post  and it works fine (thanks!).

I was jsut expecting those links to be re-written automatically, like they would in web forms, but i guess this is handled differently for mvc razor? 

Dec 08, 2014 16:49

So webforms does work differently as they use a url rewrite provider and in mvc, they use mvc's routing so it is two different technologies.  Sorry for the misunderstanding of your post.  I guess i didnt see that portion.  But in mvc, this is how you have to do it.  Sorry for the confusion.

Dec 08, 2014 16:51

Ok no worries, thanks for the heads up.

Dec 08, 2014 17:03
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.