I am trying to do something like this in my view:

@if (AuthorizedFor(MyNameSpace.Security.Permissions.Client))
{
    <p>This is the Client view</p>
}
else if (AuthorizedFor(MyNameSpace.Security.Permissions.Manager))
{
    <p>This is the Manager view</p>
}

My permissions include Manager and Client, with Client having ImpliedBy = new[] { Manager }. Manager is sterotyped to Admin role, and Client to the Contributor role.

My expectation is that if the Manager is logged in they will only see the Manager view. However, because Manager has Client rights, the logic displays the first only (Client view). If I make both an if statement, then both pop up. When logged in as a Client I only see the Client view.

This makes sense, however, is it possible to code around that without having to do anything major? I am using my own front-end not tied to parts, so the ContentPermission module is not an option.

有帮助吗?

解决方案

Something like this

@if (AuthorizedFor(MyNameSpace.Security.Permissions.Client))
{
    if (AuthorizedFor(MyNameSpace.Security.Permissions.Manager) {
        <p>This is the Manager view</p>
    } else {
        <p>This is the Client view</p>
    }
}

其他提示

Do as you did, but start with the most powerful role:

@if (AuthorizedFor(MyNameSpace.Security.Permissions.Manager))
{
    <p>This is the Manager view</p>
}
else if (AuthorizedFor(MyNameSpace.Security.Permissions.Client))
{
    <p>This is the Client view</p>
}

You can extend this to more roles, as long as it comes to the most powerful role first a user will always be shown the most powerful options that their role membership allows.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top