2011-02-09 76 views
1

我上一個帖子,您可以使用ASP.Net授權在網絡配置來控制訪問一個WCF Web服務,以取代以下屬性閱讀:無法設定授權規則在web.config中的WCF服務

[PrincipalPermission(SecurityAction.Demand, Role="Administrators")] 

測試我一直在使用「管理員」這是一個有效的角色,所以應該允許我訪問和「測試」這是沒有。

<authentication mode="Windows" /> 
<authorization> 
    <allow roles=".\TEST"/> 
    <deny roles="*"/> 
</authorization> 

它仍然可以讓我訪問:使用上述屬性時,但是當我評論說出來,在我的web.config文件中使用此這工作得很好。

所以我想知道如果我剛剛在web.config中出現了錯誤,或者我讀的是否錯誤地說使用它。

僅供參考,這是我看着帖子:

Using Windows Role authentication in the App.config with WCF

和下面是我的web.config:

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <authentication mode="Windows" /> 
    <authorization> 
     <allow roles=".\TEST"/> 
     <deny users="*"/> 
    </authorization> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpEndpointBinding"> 
      <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="WcfService1.ServiceBehaviour1" name="WcfService1.Service1"> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" 
        name="BasicHttpEndpoint" contract="WcfService1.IService1"> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WcfService1.ServiceBehaviour1"> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

感謝。

回答