Code examples
Below you find a list of code examples that have been added for this attribute.
Language:
C#
Posted by:
Imar Spaanjaars
Date added:
3/25/2010
If you just use the Authorize attribute as-is, the method can be called by any logged in user:
[Authorize]
public ActionResult SomeBlockedMethod() { ... }
If you want to block the method for anyone except specific users or roles, you can use the Roles or Users properties of the attribute:
[Authorize(Roles="Administrators, Managers")]
public ActionResult SomeBlockedMethod() { ... }
[Authorize(Users="Imar, John")]
public ActionResult SomeBlockedMethod() { ... }
If you want to add a code example, you need to
log in first. Don't have account? You can
sign up for one right now.