簡體   English   中英

具有成員資格提供程序身份驗證的WCF WebHttpBinding

[英]WCF WebHttpBinding with Membership provider authetication

我有一個使用基本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>

此配置將不起作用。 但是有解決此問題的方法:

  • 創建Login()方法並使用身份驗證令牌,該令牌將傳遞給每個服務方法。
  • 使用自定義驗證模式,並使用Membership.ValidateUser()通過代碼驗證用戶名\\密碼

令牌通過登錄名或自定義http身份驗證模塊傳遞。

這是自定義身份驗證模塊的鏈接。 http://custombasicauth.codeplex.com/

對於基於令牌的,您可以使用OAuth實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM