嗨,我在为 Web 应用程序设置管理模块时遇到问题
我的系统管理员和技术人员有两个角色
如果转到管理员模块,系统将查看他是否是管理员
如果用户不是管理员,则将他重定向到页面
抱歉,您无权访问此页面!
我使用 Web.config 来限制对子目录 Admin 的访问
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<allow roles="admin" />
<deny users="*"/>
</authorization>
</system.web>
</configuration>
我也有 C# 代码来检查登录用户是管理员还是其他
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (Page.User.IsInRole("admin"))
{
if (!Page.IsPostBack)
{
DisplayRolesInGrid();
}
}
if(!Page.User.IsInRole("admin"))
{
Response.Redirect("/accessPage.aspx");
}
}
}