RequiresAuthenticationAttribute Class
[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]
Specifies that a domain operation can only be invoked by an authenticated user.
System.Attribute
System.ComponentModel.DataAnnotations.AuthorizationAttribute
System.ServiceModel.DomainServices.Server.RequiresAuthenticationAttribute
Namespace: System.ServiceModel.DomainServices.Server
Assembly: System.ServiceModel.DomainServices.Server (in System.ServiceModel.DomainServices.Server.dll)
The RequiresAuthenticationAttribute type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | RequiresAuthenticationAttribute | Initializes a new instance of the RequiresAuthenticationAttribute class. |
| Name | Description | |
|---|---|---|
![]() | ErrorMessage | Gets or sets the literal error message or resource key intended to be returned in an ErrorMessage. (Inherited from AuthorizationAttribute.) |
![]() | ResourceType | Gets or sets the Type to use as the resource manager for ErrorMessage. (Inherited from AuthorizationAttribute.) |
![]() | TypeId | (Inherited from Attribute.) |
| Name | Description | |
|---|---|---|
![]() | Authorize | Determines whether the given principal object is authorized to perform a specific operation described by the given AuthorizationContext. (Inherited from AuthorizationAttribute.) |
![]() | Equals | (Inherited from Attribute.) |
![]() | Finalize | (Inherited from Object.) |
![]() | FormatErrorMessage | Gets the formatted error message for the current AuthorizationAttribute to present to the user. (Inherited from AuthorizationAttribute.) |
![]() | GetHashCode | (Inherited from Attribute.) |
![]() | GetType | (Inherited from Object.) |
![]() | IsAuthorized | Implementation specific method to determine whether the given IPrincipal object is authorized to perform a specific operation described by the given AuthorizationContext object. (Inherited from AuthorizationAttribute.) |
![]() | IsDefaultAttribute | (Inherited from Attribute.) |
![]() | Match | (Inherited from Attribute.) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | ToString | (Inherited from Object.) |
You apply the RequiresAuthenticationAttribute attribute to a domain method to restrict access to the operation to only authenticated users. When you apply the RequiresAuthenticationAttribute attribute to an entire domain service class, all of the domain operations are restricted to only authenticated users. The RequiresAuthenticationAttribute attribute prevents the method from being executed when the user is not authenticated. If you call a domain operation when the user is not authenticated, the domain operation returns an exception. You can avoid this situation by checking the IsAuthenticated property on the User object generated in the client project before calling the domain operation.
RIA Services also provides the RequiresRoleAttribute attribute to indicate that the user must belong to specified role or roles. You can also provide customized authorization requirements by implementing a class that derives from the AuthorizationAttribute and overriding the IsAuthorized method. For more information, see How to: Create a Custom Authorization Attribute.
The following example shows a domain service with the RequiresAuthenticationAttribute attribute applied to the GetSalesOrderHeader method.
[EnableClientAccess()] public class AdventureWorksDomainService : LinqToEntitiesDomainService<AdventureWorksLT_DataEntities> { [RequiresRole("Managers")] public IQueryable<Customer> GetCustomers() { return this.ObjectContext.Customers; } public IQueryable<Product> GetProducts() { return this.ObjectContext.Products; } [RequiresAuthentication()] public IQueryable<SalesOrderHeader> GetSalesOrderHeaders() { return this.ObjectContext.SalesOrderHeaders; } }
