简体   繁体   English

具有成员资格提供程序身份验证的WCF WebHttpBinding

[英]WCF WebHttpBinding with Membership provider authetication

I have a WebHttpBinding service which uses basic HTTP authentication mode, however for some strange reason it validates provided username/password against windows accounts, thought i specified userNamePasswordValidationMode="MembershipProvider". 我有一个使用基本HTTP身份验证模式的WebHttpBinding服务,但是出于某种奇怪的原因,它会针对Windows帐户验证提供的用户名/密码,以为我指定了userNamePasswordValidationMode =“ MembershipProvider”。

I found other posts that report this problem too, but no answer to this situation have been given. 我发现其他帖子也报告了此问题,但是没有给出这种情况的答案。

  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="WebBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EPWeb">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="SqlProvider" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Foo">
        <endpoint address="Test" behaviorConfiguration="EPWeb"
            binding="webHttpBinding" bindingConfiguration="WebBinding"
            contract="Foo.IService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:3456/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

This configuration will not work. 此配置将不起作用。 But there are workarounds to this issue: 但是有解决此问题的方法:

  • Create Login() method and use authentication token, which you pass to every service method. 创建Login()方法并使用身份验证令牌,该令牌将传递给每个服务方法。
  • Use custom validation mode, and validate username\\password by code, using Membership.ValidateUser() 使用自定义验证模式,并使用Membership.ValidateUser()通过代码验证用户名\\密码

Token passed login or a custom http authentication module. 令牌通过登录名或自定义http身份验证模块传递。

Here is a link to a custom authentication module. 这是自定义身份验证模块的链接。 http://custombasicauth.codeplex.com/ http://custombasicauth.codeplex.com/

For token based, you could use an OAuth implementation. 对于基于令牌的,您可以使用OAuth实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM