UrlResolver.Current.GetUrl Returning Null

Vote:
 

I have a page which returns the ContentType name and the Url of every page on our site, its purpose is for an automated test to browse each URL and check that a 200 is returned. This page uses the following to return its friendly URL:

public UrlBuilder GetFriendlyUrl(PageData page)
{  
  UrlBuilder urlBuilder = new UrlBuilder(page.LinkURL);  
  Global.UrlRewriteProvider.ConvertToExternal(urlBuilder, page.PageLink, Encoding.UTF8);
  return urlBuilder;
}

In the case of one particular ContentType, this returns a url that looks like this, in every instance of that ContentType :

"/link/8b5c1e86a4b54110ba7a311a691de448.aspx?id=9485&epslanguage=en"

Other points to note...

  • This works correctly for all of the pages on our site except for pages of this contenttype.
  • If I call UrlResolver.Current.GetUrl on its contentLink, it returns null. 
  • There is nothing different about this contenttype compared to other types we are using.
  • This worked correctly before we upgraded from 6R2 to 7.5.
  • This ContentType was created after we upgraded, although other types have been created since then, and they work fine. 

I've tried a load of OOTB ways of getting external URL from ContentReference, PageData etc and nothing returns a nice, friendly URL. When our automated test tries to browse to this dodgy-looking URL, it fails. 

Can anyone enlighten me as to what's going on here?

Cheers

#116837
Feb 05, 2015 15:44
Vote:
 

Does the content type in question have a Page template (that is a template that can render the content in it's own request, like a WebForm, Mvc Controller or a HttpHandler)? By default UrlResolver checks that the content has a valid template otehrwise it returns null (since browsing the url will result in a 404).

You can however force the UrlResovler to generate urls even if there is no template for the content. You do this by using the overload that takes a VirtualPathArgument and there specify ValidateTemplate=false

#116840
Feb 05, 2015 16:14
Vote:
 

Thanks Johan, the ContentType does have a template associated with it, but it's a template shared with other ContentTypes, if that makes any difference. I've tried what you suggested though and that did work, thanks for your help!

#116844
Feb 05, 2015 16:29
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.