Try our conversational search powered by Generative AI!

Check if Page Exists using url



I have an url to a page, how can I check if this page exists? 

Using UrlResolver.Current.Route(url); doesn't work - it returns null. It is probably because simple address has being set for this page.

I need to check if page exsits because I am constructing url from what editors are providing. And for same cases page doesn't exsit and then I need to provide different fallback url. 

Any help or suggestions much appriciated! 

Apr 17, 2018 14:15

Could this work?

using (var webClient = new WebClient())
   try {
      Stream strm = webClient.OpenRead("");    
   catch (WebException we) {
      throw we;
Apr 17, 2018 14:29

var pageRef = PermanentLinkUtility.GetPageReference(url);

Apr 17, 2018 14:45

Both solutions doesn't work - when opening stream I am getting :

{"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."}

Even when page exists (efter redirects) 

And when using 

PermanentLinkUtility.GetContentReference(urlBuilder); or PermanentLinkUtility.GetGuid(url); I am getting null and empty Guid. 

Any more ideas? 

Apr 17, 2018 15:00
IUrlResolver urlResolver;
var content = urlResolver.Route(new UrlBuilder(url));

Of course inject the IUrlResolver instance from the constructor.

Edited, Apr 18, 2018 17:03


should work both for simple address and hierarchichal routes. What does the url look like, is it absolute (that is which scheme and protocol)? If you run it through browser do you get a non 404 response?

Apr 19, 2018 12:25

Unfortunelty none of the answers are working for me. We are using https protocol and the issue is with the fact that simple adress has been set.

May 08, 2018 8:37

Marta, what do you pass in to function?
You should not pass in the absolut url I think

May 08, 2018 9:09

It should be fine to use absolute url as well but if you do the host must be listed under some site in "Manage Websites" in admin mode (to avoid routing unknown hosts like e.g.

May 08, 2018 9:29
* 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.