是否可以使用 securityTrimmingEnabled=true 阻止页面打开

发布于 2024-09-02 22:48:55 字数 411 浏览 3 评论 0原文

我有可以正常协同工作的自定义 SiteMapProvider 和 RoleProvider:如果请求的页面的 SiteMapNode.Roles 中未提及当前用户的角色,IsAccessibleToUser 返回 false

因此面包屑或菜单不显示项目。

但用户仍然可以直接输入现在显示的 URL 并打开页面。我怎样才能阻止这种行为?

我还有下一个 Web.config 设置:

<authorization>
    <allow roles="Admin,Manager,Client"  />
    <deny users="*" />
</authorization>

I have custom SiteMapProvider and RoleProvider that works together properly: IsAccessibleToUser returns false if current user's role isn't mentioned in SiteMapNode.Roles for page requested.

So breadcrumbs or menu doesn't show an item.

But user still can type now showed URL directly and open a page. How can I block such behavior?

Also I have next Web.config settings:

<authorization>
    <allow roles="Admin,Manager,Client"  />
    <deny users="*" />
</authorization>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写给空气的情书 2024-09-09 22:48:55
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();
    }
}
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();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文