.net 无法在web.config中为WCF服务设置授权规则
我在一篇文章中读到,您可以在web配置中使用ASP.Net授权来控制对WCF web服务的访问,以替换以下属性:.net 无法在web.config中为WCF服务设置授权规则,.net,asp.net,wcf,web-config,authorization,.net,Asp.net,Wcf,Web Config,Authorization,我在一篇文章中读到,您可以在web配置中使用ASP.Net授权来控制对WCF web服务的访问,以替换以下属性: [PrincipalPermission(SecurityAction.Demand, Role="Administrators")] 为了测试,我一直在使用“Administrators”,这是一个有效的角色,所以应该允许我访问,而“test”则不是。当使用上述属性时,这很好,但是当我将其注释掉并在我的Web.Config文件中使用时: <authentication mo
[PrincipalPermission(SecurityAction.Demand, Role="Administrators")]
为了测试,我一直在使用“Administrators”,这是一个有效的角色,所以应该允许我访问,而“test”则不是。当使用上述属性时,这很好,但是当我将其注释掉并在我的Web.Config文件中使用时:
<authentication mode="Windows" />
<authorization>
<allow roles=".\TEST"/>
<deny roles="*"/>
</authorization>
下面是我的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>
谢谢。如果WCF与ASP.NET一起使用,则ASP.NET授权规则不用于WCF服务。要使用它们,您必须将WCF服务转到。如果WCF与ASP.NET一起使用,则ASP.NET授权规则不用于WCF服务。要使用它们,您必须将WCF服务转到