是否可以使用SecurityTrimmingenabled = true阻止页面打开
-
04-10-2019 - |
题
我有自定义的SiteMappRovider和Roleprovider,可以正常合作: IsAccessibleToUser
返回 false
如果当前用户的角色未提及 SiteMapNode.Roles
对于请求的页面。
因此,面包屑或菜单不显示项目。
但是用户仍然可以直接显示URL并打开页面。我该如何阻止这种行为?
我也有下一个web.config设置:
<authorization>
<allow roles="Admin,Manager,Client" />
<deny users="*" />
</authorization>
解决方案
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
var roles = node.Roles.OfType<string>();
if (roles.Contains("*") || (roles.Count(r => context.User.IsInRole(r)) > 0))
{
return true;
}
else
{
throw new InsufficientRightsException();
}
}
不隶属于 StackOverflow