3

I'm trying to do something like this:

   [CustomAuthorize(Permissions = new[] { /*These are Enums */Permissions.CanChangeProducts.ToString(), Permissions.CanChangeNames.ToString()})]
    public ActionResult MyMethod()
    {
        return View();
    }

It gives the error:

Error 5 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type [...]

I've managed to put Resource string into validationattibutes, but I could'n manage to put this enum (string) array into a authorize attribute... How can I do that? Any help would be appreciated!

Victor Franchi
  • 163
  • 4
  • 16

1 Answers1

4
enum.Value | enum.Value | enum.Value

What about flags?

Like this:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Enum)]

Edit: By the way, there is very interesting answer: https://stackoverflow.com/a/270231/2524304

Community
  • 1
  • 1
Maxim Zhukov
  • 10,060
  • 5
  • 44
  • 88
  • Ok, I'm putting these enums inside a string[] variable inside a custom authorization class that inherits the authorizeAttribute... How can I use the flag? Because the number of parameters that the 'Permission' array receives variates – Victor Franchi Jul 24 '13 at 20:23
  • Edited, added link to possible answer – Maxim Zhukov Jul 24 '13 at 20:29
  • Okay! I went on the link you send and I got an answer... I just had to put the enum array itself inside the class and it worked! haha thanks... I'm still gonna try to use flags for this! – Victor Franchi Jul 24 '13 at 20:38