Try our conversational search powered by Generative AI!

Url rewriting

Vote:
 

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?  

#114213
Dec 07, 2014 15:14
Vote:
 

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).

#114214
Dec 07, 2014 19:52
Vote:
 

Hi Joshua, we are using mvc with razor.

#114232
Dec 08, 2014 10:00
Vote:
 

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.

#114252
Dec 08, 2014 15:31
Vote:
 

Hi Joshua, sure.

Using an episerver url field:

public virtual Url TargetUrl { get; set; }

markup

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

output

http://london.barratt.local/link/ca0fb5a5d257415383fba09c4dde432f.aspx?id=96

Using an episerver typed page field:

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

markup

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

output

http://london.barratt.local/link/47dca4f6a5e84447b23f4591278cf458.aspx?id=14&epslanguage=en

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.

#114253
Dec 08, 2014 16:03
Vote:
 

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.

#114254
Dec 08, 2014 16:20
Vote:
 

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? 

#114256
Dec 08, 2014 16:49
Vote:
 

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.

#114257
Dec 08, 2014 16:51
Vote:
 

Ok no worries, thanks for the heads up.

#114258
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.