【发布时间】:2014-11-06 07:40:24
【问题描述】:
我正在开发一个带有 sql 成员资格提供程序的 Web 应用程序。 我已经在 SQL 中为用户映射了角色,并且用户被正确分配给角色。 以下代码工作正常。
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;
}
}
但我想在我的配置中执行所有访问拒绝逻辑。 以下代码不起作用。具有所有角色的用户无论其角色如何都会被重定向。
<location path="Users">
<system.web>
<authorization>
<allow roles="admin"/>
<deny roles="user"/>
</authorization>
</system.web>
请让我知道我做错了什么?
【问题讨论】:
标签: c# web-config authorization asp.net-membership asp.net-roles