共用方式為


<serviceAuthorization> 元素

指定授權存取服務操作的設定

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceAuthorization>

語法

<serviceAuthorization impersonateCallerForAllOperations="Boolean"
                      principalPermissionMode="None/UseWindowsGroups/UseAspNetRoles/Custom"
                      roleProviderName="String"
                      serviceAuthorizationManagerType="String">
  <authorizationPolicies>
    <add policyType="String" />
  </authorizationPolicies>
</serviceAuthorization>

屬性和元素

以下章節描述屬性、子元素與父元素:

Attributes

Attribute Description
冒充全營運的通話者 一個布林值,指定服務中的所有操作是否都冒充呼叫者。 預設值為 false

當特定服務操作冒充呼叫者時,執行緒上下文會切換到呼叫者上下文,然後才執行指定的服務。
principalPermissionMode 設定用於在伺服器上執行操作的主體。 包括下列值:

- None
- UseWindowsGroups
- UseAspNetRoles
- Custom

預設值是 UseWindowsGroups。 該值為類型 PrincipalPermissionMode。 欲了解更多使用此屬性的資訊,請參閱 「如何:限制存取權限與 PrincipalPermissionAttribute 類別」。
roleProviderName 一個字串,指定角色提供者的名稱,提供 Windows 通訊基礎(WCF)應用程式的角色資訊。 預設值是空字串。
ServiceAuthorizationManagerType 一個包含服務授權管理器類型字串的字串。 如需詳細資訊,請參閱ServiceAuthorizationManager

子專案

元素 Description
authorizationPolicies 包含一組授權政策類型,可透過關鍵字 add 新增。 每個授權政策都包含一個必須 policyType 屬性,即字串。 屬性指定授權政策,允許將一組輸入權利要求轉換為另一組權利要求。 存取控制可以根據這些資訊被授予或拒絕。 如需詳細資訊,請參閱AuthorizationPolicyTypeElement

父元素

元素 Description
<態度> 包含服務行為的一系列設定。

備註

本節包含影響授權、自訂角色提供者及冒充的元素。

屬性 principalPermissionMode 指定授權使用受保護方法時應使用的使用者群組。 預設值為 UseWindowsGroups ,並指定 Windows 群組,如「管理員」或「使用者」,會被搜尋試圖存取資源的身份。 您也可以指定UseAspNetRoles使用在 system.web> 元素下<設定的自訂角色提供者,如下程式碼所示:

<system.web>
  <membership defaultProvider="SqlProvider"
              userIsOnlineTimeWindow="15">
    <providers>
      <clear />
      <add name="SqlProvider"
           type="System.Web.Security.SqlMembershipProvider"
           connectionStringName="SqlConn"
           applicationName="MembershipProvider"
           enablePasswordRetrieval="false"
           enablePasswordReset="false"
           requiresQuestionAndAnswer="false"
           requiresUniqueEmail="true"
           passwordFormat="Hashed" />
    </providers>
  </membership>
  <!-- Other configuration code not shown. -->
</system.web>

以下代碼顯示 roleProviderName 使用條件 principalPermissionMode

<behaviors>
  <behavior name="ServiceBehaviour">
    <serviceAuthorization principalPermissionMode ="UseAspNetRoles"
                          roleProviderName ="SqlProvider" />
  </behavior>
  <!-- Other configuration code not shown. -->
</behaviors>

關於使用此組態元素的詳細範例,請參見授權 服務操作 存取與 授權政策

另請參閱