簡體   English   中英

如何使用WCF滿足IIS基本身份驗證

[英]How can I satisfy IIS Basic Authentication with WCF

我正在嘗試使用WCF在IIS上進行基本身份驗證。

我開發了RESTFul Web服務並啟用了SSL。 我通過傳遞user namepassword

HttpContext.Current.Request.Headers["Authorization"],

並且我使用這些信息將HttpContext.Current.User設置為新的genericPrincipal()

最終,屬性HttpContext.Current.User.Identity.IsAuthenticated保持為“ true”,但是我收到的響應為"401 Unauthorized" 所以我的問題是,我如何才能滿足IIS基本身份驗證?

Web配置

<?xml version="1.0" encoding="UTF-8"?>
            <system.serviceModel>
               <services>
                  <service name="Agfa.ChannelServiceRest.PrivateServices" behaviorConfiguration="PrivateBehaviors">
                     <endpoint contract="Agfa.ChannelServiceRest.IPrivateServices" 
                               binding="webHttpBinding" 
                               bindingConfiguration="Secure" 
                               behaviorConfiguration="Web" 
                               name="PrivateBehaviors" />
                  </service>
               </services>
               <bindings>
                  <webHttpBinding>
                     <binding name="Secure">
                        <security mode="Transport">
                           <transport clientCredentialType="Basic" />
                        </security>
                     </binding>
                  </webHttpBinding>
               </bindings>
               <behaviors>
                  <endpointBehaviors>
                     <behavior name="Web">
                        <webHttp />
                     </behavior>
                  </endpointBehaviors>
                  <serviceBehaviors>
                     <behavior name="PrivateBehaviors">
                        <serviceMetadata httpsGetEnabled="true" />
                        <serviceDebug includeExceptionDetailInFaults="false" />
                     </behavior>
                  </serviceBehaviors>
               </behaviors>
               <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
            </system.serviceModel>`

您是否以正確的格式傳遞憑據以進行基本身份驗證?

授權基本-base64(用戶名:密碼)

 string credentials = string.Format("{0}:{1}", _username, _password);
 requestProperty.Headers["Authorization"] = string.Format("Basic {0}", Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(credentials)));

因此,此鏈接描述了類似的問題。

我發現了問題! IIS僅允許Active Directory用戶。 因此,要在IIS上使用基本身份驗證,您需要添加希望授予對Microsoft Active Directory訪問權限的用戶。

暫無
暫無

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

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