Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Roberto Bianchi 137 posts 446 karma points c-trib
    Mar 14, 2017 @ 15:19
    Roberto Bianchi
    0

    Get canonical url with https on razor

    Until now, to get the canonical url in a page, i'd used this razor code:

    <link rel="canonical" href="@Umbraco.NiceUrlWithDomain(CurrentPage.id)" />
    

    But the problem is that this code creates an url on http... Not on https...

    How can I solve it?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 14, 2017 @ 15:21
    Alex Skrypnyk
    1

    Hi Bob

    Try to use this code:

        string url = Request.Url.Authority + Request.RawUrl;
    
        if (Request.ServerVariables["HTTPS"] == "on")
        {
            url = "https://" + url;
        }
        else
        {
            url = "http://" + url;
        }
    

    Thanks,

    Alex

  • Roberto Bianchi 137 posts 446 karma points c-trib
    Mar 14, 2017 @ 15:37
    Roberto Bianchi
    0

    Hi Alex and thank you for your quick response.

    Your code doesn't fit in my case 'cause if the page you request had an internal redirect it doesn't appear on the canonical tag...

    Thank you the same!

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 14, 2017 @ 15:22
    Michaël Vanbrabandt
    1

    Hi Bob,

    check the web.config and search for umbracoUseSSL and set this to true.

    <add key="umbracoUseSSL" value="true" />
    

    Then it will be https!

    Hope this helps!

    /Michaël

  • Roberto Bianchi 137 posts 446 karma points c-trib
    Mar 14, 2017 @ 15:39
    Roberto Bianchi
    0

    I try your solution and it works on a domain. But on another domain it doesn't do the code changement to https. And another problem is that with this code on the web.config I can't access to umbraco backoffice.

    Really strange...

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 14, 2017 @ 15:42
    Michaël Vanbrabandt
    0

    Hi Bob,

    you mean you have multiple domains in one Umbraco installation?

    /Michaël

  • Roberto Bianchi 137 posts 446 karma points c-trib
    Mar 14, 2017 @ 15:46
    Roberto Bianchi
    0

    No, sorry, I have not explained well...

    On a website this web.config change works. On another not, and I've the problem that I explain above.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 14, 2017 @ 15:48
    Michaël Vanbrabandt
    0

    Do both website use the same version of Umbraco? Which versions do they have and on which one it works and on which one it doens't work?

    /Michaël

  • Roberto Bianchi 137 posts 446 karma points c-trib
    Mar 14, 2017 @ 15:52
    Roberto Bianchi
    0

    They both have the 7.2.7 Umbraco Version.

Please Sign in or register to post replies

Write your reply to:

Draft