How to authorize imperatively

J.D. Meier, Jason Taylor, Prashant Bansode, Carlos Farre, Madhu Sundararajan, Steve Gregersen.

Authorize windows groups imperatively by using the Roles.IsUserInRole method to authorize the client. The role can be contained in a variable and changed dynamically if needed, as shown below:
  string RequiredGroup = “Administrators”;
  try
  {
    if (!Roles.IsUserInRole(User.Identity.Name, “RequiredGroup”))
    {
      Msg.Text = "You are not authorized to view user roles.";
      UsersListBox.Visible = false;
      return;
    }
  }
  catch (HttpException e)
  {
    Msg.Text = "There is no current logged on user. Role membership cannot be verified.";
    return;
  }

Additional Resources

Last edited May 8, 2008 at 12:13 AM by prashantbansode, version 1

Comments

No comments yet.