Copied to clipboard

Flag this post as spam?

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


  • Meni 281 posts 539 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://@urlRequest.Host@urlRequest.Path as Huw Reddick suggested

    So I have

    <div class="fb-like" data-href="@urlRequest.Scheme://@urlRequest.Host@urlRequest.Path" 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://@urlRequest.Host@urlRequest.Path 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 167 posts 543 karma points MVP 2x 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 281 posts 539 karma points
    Mar 02, 2023 @ 05:23
    Meni
    0

    Thanks! work.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies