Copied to clipboard

Flag this post as spam?

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


  • Meni 271 posts 528 karma points
    Mar 01, 2023 @ 05:26
    Meni
    0

    UrlWithDomain() in Umbraco 11

    Hi,

    In my Umbraco 7 I got the page url the following:

    @Model.Content.UrlWithDomain()
    

    (I need it for the facebook share button in a page

    <div class="fb-like" data-href="@Model.Content.UrlWithDomain()" data-width="" data-layout="box_count" data-action="like" data-size="small" data-share="true"></div>
    

    It doesn't work in Umbraco 11, so I did something like:

    First injecting @inject Microsoft.AspNetCore.Http.IHttpContextAccessor _httpContextAccessor

    then @urlRequest.Scheme://@[email protected] as Huw Reddick suggested

    So I have

    <div class="fb-like" data-href="@urlRequest.Scheme://@[email protected]" data-width="" data-layout="box_count" data-action="like" data-size="small" data-share="true"></div>
    

    But is seems it takes some 1/2 seconds every time the page loads - is there a simple, faster way to do it ?

    Something similar to @Model.Content.UrlWithDomain() ?

    (btw, the @urlRequest.Scheme://@[email protected] works well for other thing I need it - for the twitter card, but for the facebook button I only need something quick and simple)

    Thanks

  • Dhanesh Kumar MJ 165 posts 521 karma points MVP c-trib
    Mar 01, 2023 @ 06:03
    Dhanesh Kumar MJ
    101

    Hi Meni,

    you can use this extension method Eg: @Model.Url(mode:UrlMode.Absolute)

  • James Cordrey 11 posts 113 karma points
    Mar 01, 2023 @ 14:06
    James Cordrey
    2

    As Dhanesh said

    @Model.Url(mode: UrlMode.Absolute) 
    

    is the normal way to go. But if you're using a strongly typed content model, say in a block, that won't work. You'll need to use this:

    @Umbraco.AssignedContentItem.Url(mode: UrlMode.Absolute)
    
  • Meni 271 posts 528 karma points
    Mar 02, 2023 @ 05:23
    Meni
    0

    Thanks! work.

Please Sign in or register to post replies

Write your reply to:

Draft