为什么 IIS 中的授权规则不会限制对我的 WCF 服务的访问?

2024-03-27

我有一个托管在 IIS 10 中的独立 WCF 服务。我想将对 Web 服务的访问限制为选定的用户组。我可以通过在 IIS 中执行以下操作来为 Web 应用程序执行此操作:

  • 身份验证:仅 Windows 身份验证(禁用匿名身份验证)
  • 授权规则:允许预定义组(即角色)

但是,当我对网络服务执行上述步骤并更改时clientCredentialType="Windows"在其 web.config 中,它仍然允许域中的任何用户与其通信。我错过了一些明显的东西吗?在配置授权方面,Web 服务的功能与 Web 应用程序是否不同?鉴于我的设置,我希望只有以下用户我的测试组能够与 Web 服务通信,而其他所有服务都会收到 401 - 未经授权。

顺便说一句,我尝试设置“拒绝所有人”规则,但域用户仍然可以与网络服务通信,所以我觉得授权设置没有以某种方式实现。寻找对此的任何见解。

以下是相关的web.config内容:

  <system.serviceModel>
    <services>
      <service name="StudyManagement.StudyManagement">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" name="StudyManagement" contract="StudyManagement.IStudyManagement" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="1048576" />
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" />
        <security>
            <authorization>
                <remove users="*" roles="" verbs="" />
                <add accessType="Allow" users="" roles="MyAllowGroup" />
            </authorization>
        </security>
  </system.webServer>

你可以参考这个website https://learn.microsoft.com/en-us/iis/manage/configuring-security/understanding-iis-url-authorization重新创建授权规则。另外,wcf服务的授权可以使用ServiceAuthenticationmanager,示例和教程。 https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/authorization-policy

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 IIS 中的授权规则不会限制对我的 WCF 服务的访问? 的相关文章

随机推荐