5

What does [Authorize(Users = "*")] mean in asp.net mvc.? Also please explain [Authorize(Users = "")] and [Authorize(Users = "?")].

Thanks.

Muthukumar
  • 8,679
  • 17
  • 61
  • 86

3 Answers3

12

To authorize all users, just omit using the [Authorize] attribute alltogether. To authorize authenticated users, use the [Authorize] attribute. To authorize specific roles or users, that is when you'll have [Authorize (Users = "someuser")] or [Authorize (Roles = "somerole")].

  • I tried [Authorize(Users = "*")] to a Action. It does not even allow authenticated users. When i add just [Authorize], it allows the authenticated users. – Muthukumar Nov 10 '11 at 16:31
  • 1
    The `[Authorize]` attribute alone is to authorize authenticated users, that is correct. –  Nov 10 '11 at 16:35
  • The start (`*`) must just be for config authorization rules, it's possible it isn't recognized in the attribute as a valid value. –  Nov 10 '11 at 16:36
  • 1
    To authorize all users, just omit using the `[Authorize]` attribute alltogether. To authorize authenticated users, use the `[Authorize]` attribute. To authorize specific roles or users, that is when you'll have `[Authorize (Users = "someuser")]` or `[Authorize (Roles = "somerole")]`. –  Nov 10 '11 at 16:38
  • Thanks folks. I fell into the same pitfall as the OP – Yablargo Jul 09 '12 at 18:09
0

Looking at the documentation for the attribute it doesn't look like you can use it that way. By default the AuthorizeAttribute only allows access to authenticated and authorised users so passing * (all) or ? (guest) doesn't make sense.
The Users property is used to further restrict the list of authenticated users who can access the Action method along with the Roles property which can also be used to further filter any authenticated access.

Andy Rose
  • 16,770
  • 7
  • 43
  • 49
0

I think the second post is correct, in [Authorize(Users = " * ")] the " * " part doesn't make any sense (in the web.config it does but that is something completely different).

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
Pat
  • 1