2

Within my application a privileged user can add/delete/update user roles (while also assigning them to specific users). The below excerpt shows a rule in my web.config file which allows the functionality of user blocking to only administrators:

<location path="block-user.aspx">
  <system.web>
    <authorization>
      <allow users="Administrator"/>
    </authorization>
  </system.web>
</location>

What if I want to dynamically add or delete other roles besides the default one? Can this be done through code-behind?

1 Answer 1

0

If you want to restrict some pages to certain roles, you can do this in Page_Load function;

    protected void Page_Load(object sender, EventArgs e)
    {
          if(!User.IsInRole(allowedrole))
          {
             Response.Redirect("block-user.aspx");
          }
          else
          {
          //do stuff
          }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.