【问题标题】:Cannot set authorization rules in web.config for WCF Service无法在 web.config 中为 WCF 服务设置授权规则
【发布时间】:2011-06-24 01:44:13
【问题描述】:

我在一篇文章中读到,您可以在 Web 配置中使用 ASP.Net 授权来控制对 WCF Web 服务的访问以替换以下属性:

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

为了测试我一直在使用“管理员”,这是一个有效的角色,所以应该允许我访问,而“测试”不是。这在使用上述属性时效果很好,但是当我将其注释掉并在我的 Web.Config 文件中使用它时:

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

它仍然允许我访问。

所以我想知道我是否只是在 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>

谢谢。

【问题讨论】:

    标签: .net asp.net wcf web-config authorization


    【解决方案1】:

    如果 WCF 是 ASP.NET 的 hosted side-by-side,则不会将 ASP.NET 授权规则用于 WCF 服务。要使用它们,您必须将您的 WCF 服务转为 ASP.NET compatibility mode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 2017-08-09
      • 1970-01-01
      相关资源
      最近更新 更多