Try our conversational search powered by Generative AI!

Hash url's for internal links are still broken

tss
tss
Vote:
 

We are still seeing issues with the hash handling for internal links

The automatic mapping of urls in the External Link to internal fails

if you have a url link this

https://www.bolia.com/da-dk/accessories/boligtekstiler/puder/#!/?facets.Family.value.raw=Classic%20cushions&facets.Family.value.raw=Craft%20PIllow

from what I see the link is converted to a Internal link correctly but mapping the other way fails

In the sample above we have a page in danish but the master language is english

When using the .ContentUrl extension method to map the url to the user friendly version the conversion fails and we get a link to the /link/{guid} with the hashbang url

when using the link we get redirected to the master language for the page without any hashbang (only natural for a redirect as the hash isn't visible on the server side)

If I change the Url to: 

https://www.bolia.com/da-dk/accessories/boligtekstiler/puder/?#!/?facets.Family.value.raw=Classic%20cushions&facets.Family.value.raw=Craft%20PIllow

note the question mark I have added

and process the url everything works correctly

from my debugging I think the issue is that the Method: PermanentLinkUtility.GetGuid(url.Path, out extension)

The method only looks for questionmark in the path and doesn't handle the hash symbol

If others have the same issue you can fix the url with this code before sending it to UrlHelper.ContentUrl():

        private const string QueryAndHash = "?#";
        private const string QueryString = "?";
        private const string Hash = "#";

        private static Url FixHashIssue(Url url)
        {
            if (url == null || url.OriginalString.IsNullOrWhiteSpace())
                return url;

            int indexOfHash = url.OriginalString.IndexOf(Hash, StringComparison.OrdinalIgnoreCase);
            if (indexOfHash > 0)
            {
                if (url.OriginalString.IndexOf(QueryString, StringComparison.OrdinalIgnoreCase) > indexOfHash)
                {
                    url = new Url(url.OriginalString.Remove(indexOfHash, 1).Insert(indexOfHash, QueryAndHash));
                }   
            } 
            return url;
        }
#138958
Sep 24, 2015 9:08
* 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.