RequiresAuthenticationAttribute クラス
認証済みユーザーによってのみ呼び出すことができるドメイン操作を指定します。
名前空間: System.ServiceModel.DomainServices.Server
アセンブリ: System.ServiceModel.DomainServices.Server (system.servicemodel.domainservices.server.dll 内)
使用方法
'使用
Dim instance As RequiresAuthenticationAttribute
構文
'宣言
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple:=False, Inherited:=True)> _
Public NotInheritable Class RequiresAuthenticationAttribute
Inherits AuthorizationAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=false, Inherited=true)]
public sealed class RequiresAuthenticationAttribute : AuthorizationAttribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field, AllowMultiple=false, Inherited=true)]
public ref class RequiresAuthenticationAttribute sealed : public AuthorizationAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=false, Inherited=true) */
public final class RequiresAuthenticationAttribute extends AuthorizationAttribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=false, Inherited=true)
public final class RequiresAuthenticationAttribute extends AuthorizationAttribute
例
GetSalesOrderHeader
メソッドに適用された RequiresAuthenticationAttribute 属性を持つドメイン サービスを次に示します。
<EnableClientAccess()> _
Public Class AdventureWorksDomainService
Inherits LinqToEntitiesDomainService(Of AdventureWorksLT_DataEntities)
<RequiresRole("Managers")> _
Public Function GetCustomers() As IQueryable(Of Customer)
Return Me.ObjectContext.Customers
End Function
Public Function GetProducts() As IQueryable(Of Product)
Return Me.ObjectContext.Products
End Function
<RequiresAuthentication()> _
Public Function GetSalesOrderHeaders() As IQueryable(Of SalesOrderHeader)
Return Me.ObjectContext.SalesOrderHeaders
End Function
End Class
[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;
}
}
解説
RequiresAuthenticationAttribute 属性をドメイン メソッドに適用して、操作へのアクセスを認証済みユーザーにのみ制限します。RequiresAuthenticationAttribute 属性をドメイン サービス クラス全体に適用すると、すべてのドメイン操作は認証済みユーザーにのみ制限されます。RequiresAuthenticationAttribute 属性を使用すると、ユーザーが認証されていない場合、メソッドの実行が阻止されます。ユーザーが認証されていない場合にドメイン操作を呼び出すと、ドメイン操作は例外を返します。ドメイン操作を呼び出す前にクライアント プロジェクトで生成された User オブジェクトの IsAuthenticated プロパティをチェックすることにより、この状況を回避できます。
RIA サービスは、RequiresRoleAttribute 属性を提供して、ユーザーは指定されたロールに属する必要があることも示します。AuthorizationAttribute から派生するクラスを実装し、IsAuthorized メソッドをオーバーライドすることによって、カスタマイズされた承認要件を提供することもできます。詳細については、「How to: Create a Custom Authorization Attribute」を参照してください。
継承階層
System.Object
System.Attribute
System.ComponentModel.DataAnnotations.AuthorizationAttribute
System.ServiceModel.DomainServices.Server.RequiresAuthenticationAttribute
スレッド セーフ
この型の public static (Visual Basic では Shared) メンバーは、スレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。
プラットフォーム
開発プラットフォーム
Windows XP Home Edition, Windows XP Professional, Windows Server 2003 、Windows Server 2008、および Windows 2000
ターゲット プラットフォーム
Change History
参照
リファレンス
RequiresAuthenticationAttribute のメンバー
System.ServiceModel.DomainServices.Server 名前空間