Copied to clipboard

Flag this post as spam?

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


  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    Dec 12, 2016 @ 07:25
    Paul Seal
    0

    Restrict front end page to user who has logged into the back end.

    Hi all

    Please could someone tell me how I can restrict a front end page (Template) to a user who has logged into the back end as an Umbraco user?

    Thanks

    Paul

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Dec 12, 2016 @ 08:30
    Alex Skrypnyk
    100

    Hi Paul,

    Do you want to hide template or page in the backoffice for some user?

    You can use this method for getting user:

    var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
    if (userTicket != null)
    {
        var currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);
    }
    

    Thanks,

    Alex

  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    Dec 12, 2016 @ 08:46
    Paul Seal
    0

    Thank Alex.

    This looks like what I need, but I am getting this error.

    Error message

    CS1061: 'System.Web.HttpContextWrapper' does not contain a definition for 'GetUmbracoAuthTicket' and no extension method 'GetUmbracoAuthTicket' accepting a first argument of type 'System.Web.HttpContextWrapper' could be found (are you missing a using directive or an assembly reference?)

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Dec 12, 2016 @ 09:18
    Alex Skrypnyk
    2

    Hi Paul,

    Add please these:

    @using Umbraco.Core;
    @using Umbraco.Core.Security;
    

    Hope it will help.

    Thanks,

    Alex

  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    Dec 12, 2016 @ 09:38
    Paul Seal
    0

    That worked perfectly. Thanks Alex.

    Kind regards

    Paul

  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    Dec 12, 2016 @ 09:42
    Paul Seal
    0

    This was the final piece I needed for a Mini package I'm going to release. I will give you credit in the description.

    Kind regards

    Paul

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Dec 12, 2016 @ 10:07
    Alex Skrypnyk
    0

    So nice to hear, thank you very much and have a successful release!

    Alex

  • 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