2014-06-06 18 views
0

我想在IIS上使用WCF進行基本身份驗證。我如何滿足IIS基本身份驗證與WCF

我開發了一個RESTFul webservice並啓用了SSL。我通過user namepassword通過

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

我用這些信息來設置HttpContext.Current.User到一個新的genericPrincipal()

最終屬性HttpContext.Current.User.Identity.IsAuthenticated保持「真實」 但是,我收到的回覆是"401 Unauthorized"。所以我的問題是,我如何滿足IIS基本認證?

的Web.Config

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

回答

0

你在路過的憑據爲基本身份驗證的正確格式?

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

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

這使link描述了一個類似的問題。

+0

是的,我會的,我做了一個視頻與我的調試,並上傳到YouTube:https://www.youtube.com/watch?v=cqtWvM8l2Kg&feature=youtu.be該視頻演示了有關用戶信息的詳細調試請求,認證,e響應狀態。 – Lindemberg

0

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