asp.net - 在 WCF 服务中使用 ASP.NET 成员资格提供程序身份验证

标签 asp.net wcf asp.net-membership wcf-security

有没有办法使用成员(member)提供者提供的相同用户名和密码进行 WCF 服务身份验证?如果是这样,它支持哪种绑定(bind)?我需要从当前调用服务的用户中提取配置文件变量。谢谢你的帮助。

最佳答案

基本上,任何接受用户名/密码作为消息安全客户端凭据的绑定(bind)都可以配置为使用 ASP.NET 成员资格提供程序。

how to use the ASP.NET Membership provider in WCF 上查看此 MSDN 文档- 您需要为“用户名”类型的客户端凭据配置绑定(bind)

<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>

以及使用 ASP.NET Membership 进行用户身份验证的服务:
<serviceBehaviors>
  <behavior name="AspNetMembership">
     <serviceCredentials>
        <userNameAuthentication 
             userNamePasswordValidationMode ="MembershipProvider" 
             membershipProviderName ="SqlMembershipProvider"/>
     </serviceCredentials>
  </behavior>
</serviceBehaviors>

当然,您必须在配置服务时将此服务行为应用于您的服务!
<services>
   <service name="YourService" behaviorConfiguration="AspNetMembership">
   ....
   </service>
</services>

BasicHttpBinding、wsHttpBinding、netTcpBinding 支持 UserName 客户端凭据类型——几乎所有常见的嫌疑人。

关于asp.net - 在 WCF 服务中使用 ASP.NET 成员资格提供程序身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2615316/

相关文章:

asp.net - 将 AJAX 回调与 ASP.NET 用户控件结合使用

asp.net - ASP.NET vNext 和 ASP.NET 5 之间有什么区别?

.net - 在 IIS Express 中托管 WCF 服务时出现问题

asp.net-mvc-3 - ASP.Net MVC 基于安全隐藏/显示菜单项

c# - 如何通过电子邮件获取 ASP.NET MembershipUser

asp.net - 获取DataPager当前页码

c# - 如何从 json 数组中读取每个数据并将其分配给 SQL Server IN 子句

wcf - 自托管 WCF 服务主机/WebServiceHost 并发/性能设计选项 (.NET 3.5)

ajax - 对 WCF 休息服务进行 Ajax 调用时出现 500 System.ServiceModel.ServiceActivationException

c# - 将一张表与自身相乘并得到一个字段是什么意思?