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?
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?
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.
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
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.
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
Hi Dan,
Sure, it's a bit rough-n-ready, but it goes a little something like this...
You could probably reverse the logic so that you don't need the "else" condition... but you get the idea.
Cheers, Lee.
Ace, thanks Lee.
is working on a reply...
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.