0

I am working on a web application with sql membership providers. I have mapped roles for the user in the SQL and the users are assigned to roles correctly. Following code works fine.

        protected void btnLogin_Click(object sender, EventArgs e)
        {
        if (Membership.ValidateUser(txtUserName.Text, txtPassWord.Text))
        {
            if (Roles.IsUserInRole(txtUserName.Text, "admin"))
            Response.Redirect("~/Users/ViewUsers.aspx");
        }
        else
        {
            lblErrorMessage.Visible = true;
        }
    }

But I want to do all the access denial logic in my config. The following code doesnt work. Users with all roles get redirected in spite of their roles.

<location path="Users">
<system.web>
  <authorization>
    <allow roles="admin"/>
    <deny roles="user"/>
  </authorization>
</system.web>

Kindly let me know what I am doing wrong ?

wickjon
  • 900
  • 5
  • 14
  • 40

3 Answers3

0

You need to use <deny users="*"/> instead. See MSDN article with example.

Max Brodin
  • 3,903
  • 1
  • 14
  • 23
0

have you try this? it will work

 [Authorize(Roles = "Super Admin,Business Admin")]
0

I had to set the formauthentication cookie to do this and all works fine now

string username = UsernameTB.Text;
FormsAuthentication.SetAuthCookie(username, false);
wickjon
  • 900
  • 5
  • 14
  • 40