共用方式為


QueryInterceptorAttribute 類別

方法上的 QueryInterceptorAttribute 標註它做為指定之實體集的查詢攔截器。

繼承階層

System.Object
  System.Attribute
    System.Data.Services.QueryInterceptorAttribute

命名空間:  System.Data.Services
組件:  Microsoft.Data.Services (在 Microsoft.Data.Services.dll 中)

語法

'宣告
<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple := True, Inherited := True)> _
Public NotInheritable Class QueryInterceptorAttribute _
    Inherits Attribute
'用途
Dim instance As QueryInterceptorAttribute
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public sealed class QueryInterceptorAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple = true, Inherited = true)]
public ref class QueryInterceptorAttribute sealed : public Attribute
[<SealedAttribute>]
[<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true, Inherited = true)>]
type QueryInterceptorAttribute =  
    class
        inherit Attribute
    end
public final class QueryInterceptorAttribute extends Attribute

QueryInterceptorAttribute 型別公開下列成員。

建構函式

  名稱 說明
公用方法 QueryInterceptorAttribute 針對 entitySetName 參數指定的實體集,初始化 QueryInterceptorAttribute 類別的新執行個體。

上層

屬性

  名稱 說明
公用屬性 EntitySetName 取得實體集的名稱,其中包含套用攔截器的實體。
公用屬性 TypeId (繼承自 Attribute。)

上層

方法

  名稱 說明
公用方法 Equals (繼承自 Attribute。)
受保護的方法 Finalize (繼承自 Object。)
公用方法 GetHashCode (繼承自 Attribute。)
公用方法 GetType (繼承自 Object。)
公用方法 IsDefaultAttribute (繼承自 Attribute。)
公用方法 Match (繼承自 Attribute。)
受保護的方法 MemberwiseClone (繼承自 Object。)
公用方法 ToString (繼承自 Object。)

上層

明確 繼承 實作

  名稱 說明
明確介面實作私用方法 _Attribute.GetIDsOfNames (繼承自 Attribute。)
明確介面實作私用方法 _Attribute.GetTypeInfo (繼承自 Attribute。)
明確介面實作私用方法 _Attribute.GetTypeInfoCount (繼承自 Attribute。)
明確介面實作私用方法 _Attribute.Invoke (繼承自 Attribute。)

上層

備註

實體集層級授權和驗證是由標註具有 QueryInterceptorAttribute 的方法所實作。 WCF Data Services 不實作安全性原則,而是提供所需的基礎結構,供服務開發人員撰寫自己的安全規則和商務驗證。

實體集存取控制和驗證是透過使用查詢組合的查詢作業來啟用。 若要控制基於實體的存取,請根據下列規則,針對每個實體集實作一個方法:

方法必須具有公用範圍和標註具有 QueryInterceptorAttribute,並接受實體集名稱做為參數。

方法必須不接受任何參數。

方法必須傳回 Expression<Func<T, bool>> 型別的運算式,就是針對實體集組成的篩選。

範例

下列範例控制 Customers 實體集的存取。 每個 Customer 只能看到與該 Customer 相關聯的 Orders。

[QueryInterceptor("Orders")]
public Expression<Func<Order, bool>> FilterOrders() 
{
    return o => o.Customer.Name == /* Current principal name. */;
} 
 
// Insures that the user accessing the customer(s) has the appropriate
// rights as defined in the QueryRules object to access the customer
// resource(s).
 
[QueryInterceptor ("Customers")]
public Expression<Func<Customer, bool>> FilterCustomers() 
{
  return c => c.Name == /* Current principal name. */ &&
              this.CurrentDataSource.QueryRules.Contains(
                rule => rule.Name == c.Name &&
                        rule.CustomerAllowedToQuery == true
              );
}

執行緒安全性

這個型別的任何公用 static (在 Visual Basic 中為 Shared) 成員都是執行緒安全的。並不是所有的執行個體成員都保證可以用於所有的執行緒。

請參閱

參考

System.Data.Services 命名空間