0

我有一个使用基本 HTTP 身份验证模式的 WebHttpBinding 服务,但是由于某些奇怪的原因,它会针对 Windows 帐户验证提供的用户名/密码,我认为我指定了 userNamePasswordValidationMode="MembershipProvider"。

我发现其他帖子也报告了这个问题,但没有给出这种情况的答案。

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

2 回答 2

0

此配置将不起作用。但是有解决这个问题的方法:

  • 创建 Login() 方法并使用身份验证令牌,您将其传递给每个服务方法。
  • 使用自定义验证模式,并通过代码验证用户名\密码,使用 Membership.ValidateUser()
于 2011-02-21T09:47:37.507 回答
0

令牌通过登录或自定义 http 身份验证模块。

这是自定义身份验证模块的链接。 http://custombasicauth.codeplex.com/

对于基于令牌,您可以使用 OAuth 实现。

于 2011-10-27T12:31:23.887 回答