Host custom WCF service with authentication within Umbraco

前提是你 提交于 2019-12-08 07:20:49

问题


I've created a custom WCF service within Umbraco. The service resides in the Service folder and seems to be working fine (I can call it and it responds appropriately). Now I want the users to authenticate themselves when they call the service.

To do this I've added these lines into the web.config:

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
 <bindings>
  <webHttpBinding>
    <binding name="RaceManBinding">
      <security mode="None" />
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="RaceManagerAdmin.RaceManDataService" behaviorConfiguration="RaceManBehavior">

    <endpoint address=""
              binding="webHttpBinding"
              contract="System.Data.Services.IRequestHandler" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="RaceManBehavior">
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
                                membershipProviderName="UmbracoMembershipProvider" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

When my service is called it should use the Umbraco membership provider to authenticate the users.

My client specificies this by creating a network credential object, like this:

var a = new RaceEntities(new Uri("http://localhost:40406/umbraco/Webservices/RaceManDataService.svc")) { Credentials = new NetworkCredential("admin", "secret") };

When I inspect the HTTPContext.Current I don't see any authenticated users.

What am I doing wrong?

Frederik


回答1:


You'll need to enable ASP.Net Compatibility in order to access the identity via the HttpContext:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>

The answer to this question mentions an alternate method: How to access HttpContext.Current.User.Username in WCF service



来源:https://stackoverflow.com/questions/14795958/host-custom-wcf-service-with-authentication-within-umbraco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!