Url.ItemDisplayUrl with custom AutoRoute

Topics: Core, Customizing Orchard, General, Troubleshooting, Writing themes
Mar 24, 2012 at 6:49 PM

Is there any way to get custom url that user entered instead of the AutoRoute one?

I've enabled custom routes for pages and blogs. The web users have started creating content and on a various occasions they changed the default generated URL. After they've done so, they expected this to be propagated on design, as did I.

On the theme side, I've been using the Url.ItemDisplayUrl() method to get the URL of content items. But that method always (at least for all pages and blog posts) returns auto generated routes and not the custom ones. 

What is the simplest way from the template to get the custom content item URL that users entered and is Url?

Currently I'm down to using this:

"/" + @item.ContentItem.AutoroutePart.Path
but I don't think it's the best solution. The best solution, at least for me, would be to modify Url.ItemDisplayUrl so that it returns the custom URL if it exists but I don't want to modify the core Orchard because I want to be able to update to newer versions of Orchard when they ship..

Coordinator
Mar 25, 2012 at 1:41 AM

Enable Alias UI and delete the old alias.

Mar 25, 2012 at 2:44 PM

OK, it works, but unfortunately that's not good enough.

On the site that I'm having issues with, there will be around 1000 produced articles, with 5-10 content editors and they won't use this since it's too complicated to find, and it should be working as intended in the first place - if they've put a custom URL in the administration, and when they go and edit that same content item, the same custom URL is shown, they expect that to be visible on the front page as well without doing anything additional. They see this as a bug, and frankly, so do I.

I suppose I'll have to wait for some further Orchard version where this would be solved, and 'till then I'll use before mentioned approach..

Coordinator
Mar 25, 2012 at 9:54 PM

We never implicitly delete an alias (that's to avoid broken links). Feel free to file a bug or fix it.

Mar 26, 2012 at 7:18 AM

I'm not advocating for deletion of aliases. I'm just saying that if there are more than 1 alias, Url.ItemDisplayUrl() should always display the one the user chose, and in this case, the user chose the custom URL.

I've filed the bug here - http://orchard.codeplex.com/workitem/18575