Using ASP.NET Membership Provider authentincation in a WCF service

我是研究僧i 提交于 2019-12-02 17:15:27

Basically any binding that accepts username/password as client credentials for message security can be configured to use the ASP.NET membership provider.

Check out this MSDN docs on how to use the ASP.NET Membership provider in WCF - you need to configure your binding for client credentials of type "UserName"

<bindings>
  <wsHttpBinding>
  <!-- Set up a binding that uses UserName as the client credential type -->
    <binding name="MembershipBinding">
      <security mode ="Message">
        <message clientCredentialType ="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

and the service to use ASP.NET Membership for user authentication:

<serviceBehaviors>
  <behavior name="AspNetMembership">
     <serviceCredentials>
        <userNameAuthentication 
             userNamePasswordValidationMode ="MembershipProvider" 
             membershipProviderName ="SqlMembershipProvider"/>
     </serviceCredentials>
  </behavior>
</serviceBehaviors>

and of course, you have to apply this service behavior to your services when configuring them!

<services>
   <service name="YourService" behaviorConfiguration="AspNetMembership">
   ....
   </service>
</services>

The UserName client credential type is supported by basicHttpBinding, wsHttpBinding, netTcpBinding - so pretty much all the usual suspects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!