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 ?