Copied to clipboard

Flag this post as spam?

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


  • dev-thandabantu 41 posts 321 karma points
    Aug 04, 2022 @ 06:58
    dev-thandabantu
    0

    HttpContext in Umbraco 10

    Hi,

    I am trying to do something similar to this solution, but in Umbraco 10 and I haven't been successful. Please help. In other words, what's the equivalent of this in Umbraco 10?

    var t = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket()

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 04, 2022 @ 11:54
    Huw Reddick
    0

    Hi,

    Not sure if this is what you need, but I am using this code in a middleware component I use to protect some Media folders

    private bool IsBackofficeUser(HttpContext context, IOptionsSnapshot<CookieAuthenticationOptions> cookieOptionsSnapshot)
    {
        CookieAuthenticationOptions cookieOptions = cookieOptionsSnapshot.Get(Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
        string backOfficeCookie = context.Request.Cookies[cookieOptions.Cookie.Name!];
        AuthenticationTicket unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
        ClaimsIdentity backOfficeIdentity = new ClaimsIdentity();
        if (unprotected != null)
        {
            backOfficeIdentity = unprotected!.Principal.GetUmbracoIdentity();
        }
        return backOfficeIdentity.IsAuthenticated;
    }
    

    The class that calls this has IOptionsSnapshot<CookieAuthenticationOptions> injected in it's constructor

  • dev-thandabantu 41 posts 321 karma points
    Aug 20, 2022 @ 15:23
    dev-thandabantu
    100

    I ended up using the content type service (IContentTypeService).

Please Sign in or register to post replies

Write your reply to:

Draft