Try our conversational search powered by Generative AI!

Check if Page Exists using url

Vote:
 

Hi,

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! 

#190817
Apr 17, 2018 14:15
Vote:
 

Could this work?

using (var webClient = new WebClient())
{
   try {
      Stream strm = webClient.OpenRead("http://www.episefesr.com");    
   }
   catch (WebException we) {
      throw we;
   }
}
#190820
Apr 17, 2018 14:29
Vote:
 

var pageRef = PermanentLinkUtility.GetPageReference(url);

#190823
Apr 17, 2018 14:45
Vote:
 

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? 

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

Of course inject the IUrlResolver instance from the constructor.

#190909
Edited, Apr 18, 2018 17:03
Vote:
 

UrlResolver.Current.Route(url); 

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?

#191037
Apr 19, 2018 12:25
Vote:
 

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.

#192123
May 08, 2018 8:37
Vote:
 

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

#192124
May 08, 2018 9:09
Vote:
 

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. https://www.google.com/someSegmentThatMightExistInCMS)

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