【问题标题】:Which IIS settings i have to use for using own password validation with WCF我必须使用哪些 IIS 设置才能通过 WCF 使用自己的密码验证
【发布时间】:2012-02-07 11:21:02
【问题描述】:

我创建了一个托管在 IIS 中的简单 WCF 服务。现在我想使用我自己的用户名身份验证。 我的 web.config:

  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="MyBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic"></transport>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="WcfIIsBasicAuthTest.Service1" behaviorConfiguration="MyBehavior">
        <endpoint address=""
            binding="basicHttpBinding"
            contract="WcfIIsBasicAuthTest.IService1"
            bindingConfiguration="MyBinding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehavior">
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WcfIIsBasicAuthTest.MyValidator, WcfIIsBasicAuthTest"/>
            </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

验证者

namespace WcfIIsBasicAuthTest
{
    public class MyValidator :UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if(!(userName == "test" && password == "test"))
            {
                throw new SecurityTokenException("Validation Failed!");
            }
        }
    }
}

如果我从 Visual Studio 中启动此 WCF 服务,我会收到以下错误:The authentication schemes configured on the host ('Ntlm, Anonymous') do not allow those configured on the binding 'BasicHttpBinding' ('Basic').

如果我尝试连接到托管在 IIS 中的服务,我会收到错误消息,具体取决于设置的身份验证类型,但它根本不起作用。

仅启用匿名身份验证时出错:The authentication schemes configured on the host ('Anonymous') do not allow those configured on the binding 'BasicHttpBinding' ('Basic').

如果我在 IIS 中设置基本身份验证,它需要一个我不想提供的有效本地用户(因为我想编写自己的 userprovider)。

任何提示/链接如何使用 wcf 和 iis 设置这样一个基本的身份验证用户提供程序?

【问题讨论】:

    标签: c# wcf iis


    【解决方案1】:

    您能否设置以下配置以使用您自己的 UserNameValidator:

    <security mode="TransportWithMessageCredential">
          <message clientCredentialType="UserName"/>
    </security>
    

    要使用 basicHttpBinding,您需要设置 HTTPS,因为 WCF 不允许用户名密码以明文形式通过通道传递。另一种选择是使用 wsHttpBinding。

    【讨论】:

    • 即使使用 https 配置网站,我也无法使用自己的用户提供程序。除此之外,'clientCredentialTyp="UserName"' 总是无效的(或者我错过了什么?)
    • 奇怪的是“clientCredentialType=UserName”无效。你能发布你得到的错误吗?
    • 它只是说:'clientCredentialType 无效' 我可以从“None,Basic,Digest,Ntml,Windows,Certificate”中选择
    • 它不是用于传输元素,而是用于安全元素中的消息元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多