Try our conversational search powered by Generative AI!

Get the contentref from external url

Vote:
 

Hi all!

I have implemented a method that checks if the previous page is of a specific pagetype. It works perfectly in our stage environment but not in production. I have checked that the property PreviousPageUrl is not an empty string in production. So it can’t be that. It has to be when it tries to get the contentreference for the page where it fails. Have I missed something? The only difference between the two environments that I can think of is that the stage environment is closed. You only access it by login into it.

Br/Isabel

        public static string PreviousPageUrl

        {

            get

            {

                var urlRef = System.Web.HttpContext.Current.Request.UrlReferrer;

                if (urlRef != null)

                {

                    return new UrlBuilder(urlRef.AbsoluteUri).ToString();

                }

                return string.Empty;

            }

        }

 

        public static string GetPreviousUrlsPageType()

        {

            if (string.IsNullOrEmpty(PreviousPageUrl)) return string.Empty;

 

            var contentRef = UrlResolver.Current.Route(new UrlBuilder(PreviousPageUrl));

            if (contentRef != null)

            {

                var page = ContentRepository.Get(contentRef.ContentLink);

                if (page is FloorGuideBasePageType)

                {

                    return PageTypes.FloorGuidePage;

                }

                if (page is ProductAccessoryDetailPageType)

                {

                    return PageTypes.ProductAccessoryDetailPageType;

                }

            }

            return string.Empty;

        }

#152680
Aug 29, 2016 10:12
Vote:
 

My guess is that it has to do with the site configuration. Do you have a site definition in admin mode that matches the host name in your PreviousPageUrl property? Maybe you have correct mapping in staging but not in production?

#153267
Aug 29, 2016 13:43
Vote:
 

I already checked that. And the site definition is correct

#153269
Aug 29, 2016 14:04
Vote:
 

Is your production site behind a proxy or similar? Some firewalls and proxies does not preserve UrlReferrer

#153272
Aug 29, 2016 14:44
Vote:
 

It cant be because I checked to see if the property PreviousPageUrl was empty or not. And it had the previous page URL in the production environment.

#154278
Aug 29, 2016 15:40
Vote:
 

If the site definition is correct I'm currently out of ideas. From what I can see the host name matching in UrlResolver is case sensitive. Is your host name mapping lowercase only?

#154281
Aug 29, 2016 16:08
Vote:
 

Code looks sound from what I can tell...

#154288
Aug 30, 2016 6:28
Vote:
 

I know now what was causing this! In my site definition we have set it to start with http://www and then the url to the site while the PreviousPageUrl did not contain the www and thats why it could'nt get the contentref from the url. 

Thank you Mattias Olsson! I apparently did not pay enough attention when looking at the settings, sorry! :)

#155365
Sep 15, 2016 9:00
Vote:
 

Sweet! Great with feedback to help others

#155369
Edited, Sep 15, 2016 9:34
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.