Eagle_f90
  • Posts: 27
  • Joined: 16/07/2014
I am trying to protect a page on my so only Forum Admins can access the page. If I do the check using

Quote:

(User.IsInRole("Administrators")) ? true : false;



and even though I am in the Administrators group on the forum the test is returning false. How can I make the check return true?
Sponsor
tsb6670
  • Posts: 5
  • Joined: 13/08/2014
The following code illustrates how to lookup a user to see if they are assigned to the YAF Administrators role. You can change the role from "Administrators" to "Registered" for the default YAF membership role.

using System.Web.Security;

protected void Page_Load(object sender, EventArgs e)
{
	// note: you need to reference the System.Web.ApplicationServices assembly
	MembershipUser user = Membership.GetUser();
	if(Roles.IsUserInRole(user.UserName, "Administrators") == true)
	{
		// do something here
	}
}

Cheers,
Tracy.
tsb6670
  • Posts: 5
  • Joined: 13/08/2014
Alternatively you can check the current Context:

if (Context.User.IsInRole("Administrators"))
{
    // do something here
}


Tracy.
Users browsing this topic
    Forum Jump  
    • You cannot post new topics in this forum.
    • You cannot reply to topics in this forum.
    • You cannot delete your posts in this forum.
    • You cannot edit your posts in this forum.
    • You cannot create polls in this forum.
    • You cannot vote in polls in this forum.

    About Us

    The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

    Powered by Resharper Donate with PayPal button

    Project Twitter Updates

    Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved