All Namespaces

  • Namespaces
    • AjaxControlToolkit
    • com
    • CrystalDecisions
    • DevExpress
    • DocumentFormat
    • Dundas
    • Ilrun
    • MediaCenter
    • Microsoft
    • MS
    • ServiceBus
    • Spaanjaars
    • SqlContracts
    • System
      • Activities
      • AddIn
      • CodeDom
      • ComponentModel
      • Configuration
      • Data
      • Design
      • Diagnostics
      • DirectoryServices
      • Drawing
      • Dynamic
      • EnterpriseServices
      • IdentityModel
      • IO
      • Linq
      • Management
      • Messaging
      • Net
      • Printing
      • Reflection
      • Resources
      • Runtime
      • Security
      • ServiceModel
      • ServiceProcess
      • Timers
      • Transactions
      • Web
        • Compilation
        • DynamicData
        • Hosting
        • Mobile
        • Mvc
        • Profile
        • Razor
        • Script
        • Services
        • UI
        • WebPages
      • Windows
      • Workflow
      • Xml
    • WindowsFormsIntegration

AuthorizeAttribute

Name: AuthorizeAttribute
Namespace: System.Web.Mvc
Inherits from: System.Web.Mvc.FilterAttribute
Short description: Represents an attribute that is used to restrict access by callers to an action method.
Added: 2009-02-14
Last modified: 2010-03-25
External help: http://msdn.microsoft.com/en-us/library/System.Web.Mvc.AuthorizeAttribute.aspx
Added by: Imar Spaanjaars
Can be used on:
Assembly Class Interface
Method Property Field
Constructor Struct Enum
Event Parameter Delegate
ReturnValue Generic Parameter Module
Available in:
  • 1.0.0.0
  • 2.0.0.0
  • 3.0.0.0
  • 4.0.0.0
Defined in:
  • System.Web.Mvc.dll (1.0.0.0)
  • System.Web.Mvc.dll (2.0.0.0)
  • System.Web.Mvc.dll (3.0.0.0)
  • System.Web.Mvc.dll (4.0.0.0)
Abstract?
No Sealed? No
Public?
Yes Internal? No
Allow multiple?
Yes Obsolete? No
 
Full description:
 
Class diagram:
This diagram is autogenerated and may contain errors.
Please report them if you find them.




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.

Links

Below you find a list of links that are relevant for this attribute.

Multiple Roles with Authorize Attribute using Enums in ASP.NET MVC | Life is a Unit Test


If you want to add a link, you need to log in first. Don't have account? You can sign up for one right now.