简体   繁体   English

如何使用WCF满足IIS基本身份验证

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

I'm trying to do a Basic Authentication on IIS using WCF. 我正在尝试使用WCF在IIS上进行基本身份验证。

I developed a RESTFul webservice and enabled SSL. 我开发了RESTFul Web服务并启用了SSL。 I pass user name and password through 我通过传递user namepassword

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

and I use these informations to set HttpContext.Current.User to a new genericPrincipal() . 并且我使用这些信息将HttpContext.Current.User设置为新的genericPrincipal()

Eventually the property HttpContext.Current.User.Identity.IsAuthenticated stay "true" However the response I receive is "401 Unauthorized" . 最终,属性HttpContext.Current.User.Identity.IsAuthenticated保持为“ true”,但是我收到的响应为"401 Unauthorized" So my question is, How can I satisfy IIS Basic Authentication? 所以我的问题是,我如何才能满足IIS基本身份验证?

Web.Config 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>`

Are you passing the credentials over in the proper format for Basic Authentication? 您是否以正确的格式传递凭据以进行基本身份验证?

Authorization Basic -base64(username:password) 授权基本-base64(用户名:密码)

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

This so link describes a similar problem. 因此,此链接描述了类似的问题。

I found the issue! 我发现了问题! IIS only allows, Active Directory users. IIS仅允许Active Directory用户。 So to use Basic Authentication on IIS you need add the users you wish give access to Microsoft Active Directory. 因此,要在IIS上使用基本身份验证,您需要添加希望授予对Microsoft Active Directory访问权限的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM