Copied to clipboard

Flag this post as spam?

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


  • Dan 1250 posts 3747 karma points admin c-trib
    Sep 21, 2010 @ 18:55
    Dan
    0

    Limit access to content page to admin only

    Hi,

    I have a content page, but I'd like only the master admin user to be able to view that page (i.e. only when they've logged into Umbraco).  Otherwise the user would just get an error or redirection.  What's the simplest way to achieve this?

    Thanks

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Sep 21, 2010 @ 20:47
    Lee Kelleher
    0

    Hi Dan,

    Are you meaning for a front-end content page?

    As far as I'm aware, there's nothing native in the core to do that - as generally Users are for the back-office and members are for the front-end.

    I'm thinking a code-snippet (in a macro), placed on the template for that page - that checks if the admin user has logged in.

    You say "master admin" - which I'm guessing you mean UserId 0 (zero)?

     

    Let me know, I'll show you an example of the code-snippet.

    Cheers, Lee.

  • Dan 1250 posts 3747 karma points admin c-trib
    Sep 21, 2010 @ 21:58
    Dan
    0

    Cheers Lee,

    Yeah, the page is a standard content page, but needs to be accessible only to the UserId 0 user.  A macro which checks the logged-in user id sounds perfect, if you have such a snippet?

    Thanks

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Sep 21, 2010 @ 23:02
    Lee Kelleher
    1

    Hi Dan,

    Sure, it's a bit rough-n-ready, but it goes a little something like this...

    protected void Page_Load(object sender, EventArgs e)
    {
        var user = umbraco.BusinessLogic.User.GetCurrent();
        if (user != null && user.IsAdmin() && user.IsRoot())
        {
            // do whatever you need to do in here.
        }
        else
        {
            Response.Redirect("~/access-denied.aspx", true);
        }
    }

    You could probably reverse the logic so that you don't need the "else" condition... but you get the idea.

    Cheers, Lee.

  • Dan 1250 posts 3747 karma points admin c-trib
    Sep 22, 2010 @ 11:13
    Dan
    0

    Ace, thanks Lee.

  • 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