How to route an url to IContent?

Vote:
 

Hi,

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));
#91342
Oct 03, 2014 4:47
Vote:
 

Hi,

Did you try with 

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

Regards,

/Q

#91343
Oct 03, 2014 6:04
Vote:
 

Yes. Tried with both.

#91345
Oct 03, 2014 6:18
Vote:
 

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 

#91353
Oct 03, 2014 9:48
Vote:
 

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.

#91366
Oct 03, 2014 11:56
Vote:
 

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.

#91367
Oct 03, 2014 12:04
Vote:
 

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.

#91368
Oct 03, 2014 12:11
Vote:
 

Hi again,

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

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