QueryInterceptorAttribute 類別

定義

方法上的 QueryInterceptorAttribute 會將它指定為指定實體集上的查詢攔截器。

public ref class QueryInterceptorAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
public sealed class QueryInterceptorAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)>]
type QueryInterceptorAttribute = class
    inherit Attribute
Public NotInheritable Class QueryInterceptorAttribute
Inherits Attribute
繼承
QueryInterceptorAttribute
屬性

範例

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

[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  
              );  
}  

備註

實體集合層級的授權與驗證是透過標註 的方法實作的 QueryInterceptorAttribute。 WCF 資料服務不實作安全政策,而是提供服務開發者撰寫安全規則與業務驗證所需的基礎設施。

實體集合的存取控制與驗證可透過查詢操作啟用,並使用查詢組合。 要控制基於實體的存取,請依照以下規則實作一個針對實體的方法集:

該方法必須具有公開作用域,並以 QueryInterceptorAttribute、 作為參數,並以實體名稱作為參數。

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

該方法必須回傳一個型別 Expression<Func<T, bool>> 為的表達式,即要為實體集合組合的過濾器。

建構函式

名稱 Description
QueryInterceptorAttribute(String)

初始化該類別的新實例 QueryInterceptorAttribute ,以設定參數 entitySetName 指定的實體集合。

屬性

名稱 Description
EntitySetName

取得包含攔截器所適用實體的實體集合名稱。

TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

(繼承來源 Attribute)
GetHashCode()

傳回這個實例的哈希碼。

(繼承來源 Attribute)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於