Try our conversational search powered by Generative AI!

How to route an url to IContent?



I have an url to a document in the internal format (/episerver/CMS/Content/globalassets/test/requirements.xlsx,,824?epieditmode=False), how can I get the corresponding IContent from that url?

I've tried with UrlResolver without any luck :(

var content = UrlResolver.Current.Route(new UrlBuilder(urlAsString));
Oct 03, 2014 4:47


Did you try with 

UrlResolver.Current.Route(new UrlBuilder(urlAsString), ContextMode.Edit); ? If you pass the ContextMode parameter, it will use Default.



Oct 03, 2014 6:04

Yes. Tried with both.

Oct 03, 2014 6:18

If it is a custom IContent implemention you need to implement EPiServer.Web.IRoutable. 

Also UrlResolver.GetUrl will return null if the content does not have a page template (meaning the link will end up in a 404 anyway), you can disable template validation for UrlResolver by using overload that takes a VirtualPathArguments and in there set ValidateTemplate=false 

Oct 03, 2014 9:48

Maybe I was a bit unclear. I don't want to generate the URL, I want to resolve the IContent from an URL. In this case it's a MediaData, hence no template, but that should only matter if I want to generate the URL I guess. And there is no overload that takes VirtualPathArguments.

Oct 03, 2014 11:56

As a side note: MediaData actually has a template, in that case the template is a HttpHandler (ContentMediaHttpHandler).

If you want to resolve a content from a url you would use UrlResolver.Route(UrlBuilder) that should handle media.

Oct 03, 2014 12:04

Alright. Then its even more strange that the above code doesn't work. I think I have to set up some more isolated tests with the above URL.

Oct 03, 2014 12:11

Hi again,

Now it seems to work when adding ContextMode.Edit as well. Not sure why it didn't work the first time.

Oct 03, 2014 17:35
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.