0
// [RequiredPermission(Permissions.ProjectManagement | Permissions.UserManagement)] //doesn't work
// [RequiredPermission(Permissions.UserManagement)] //works
[RequiredPermission(Permissions.ProjectManagement)] //works
public ActionResult Index() {}

Working with the attribute for the method above I can't seem to get the bitwise or to work. I thought the or would work here can anyone explain why it doesn't?

Because this works: [RequiredPermission(Permissions.UserManagement)]

This works: [RequiredPermission(Permissions.ProjectManagement)]

But this doesn't: [RequiredPermission(Permissions.ProjectManagement | Permissions.UserManagement)]

It doesn't throw any exceptions?

Here are our flags:

[Flags]
    public enum Permissions : int
    {
        None = 0x0,
        Recruiting = 0x1,
        ProjectManagement = 0x2,
        UserManagement = 0x4,
        SystemManagement = 0x8,
    }

Is there an alternative way to do this?

I am trying to require either permission to enter. It doesn't work meaning that It wont let the ProjectManagement user in when using them together. Like [RequiredPermission(Permissions.ProjectManagement | Permissions.UserManagement)]. No exceptions are thrown.

tereško
  • 58,060
  • 25
  • 98
  • 150
allencoded
  • 7,015
  • 17
  • 72
  • 126
  • It's not clear what you mean by "works" in the first place. Are you trying to require *both* permissions or *either* of them? – Jon Skeet Oct 14 '13 at 14:55
  • sorry edited i am trying to require either permission to enter – allencoded Oct 14 '13 at 14:58
  • And what behaviour are you seeing? (Again, you've only said it "doesn't work" rather than the exact symptoms.) – Jon Skeet Oct 14 '13 at 14:59
  • You need to use bitwise logic to check if a flag is set. `bool HasPermission(Permissions actual, Permissions value) { return (actual & value) == value; }` – Dustin Kingen Oct 14 '13 at 15:03

0 Answers0