如何我通过登录从ASP.Net Web应用程序用户的详细情况WCF服务? [英] How can I pass logged on user details from ASP.Net web app to WCF service?

查看:138
本文介绍了如何我通过登录从ASP.Net Web应用程序用户的详细情况WCF服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个Web应用程序:一个是ASP.Net Web应用程序,另一个是一个ASP.Net WCF Web服务应用程序。我想Web应用程序到WFC Web应用程序的使用服务。最终,这些应用程序2将通过防火墙进行通信。

I have 2 web applications: one is an ASP.Net web app and the other is an ASP.Net WCF web services application. I want to the web app to the WFC web app's consume services. Eventually, these 2 apps will be communicating over a firewall.

我希望用户使用窗体身份验证,通过WCF服务身份验证登录到客户端Web应用程序,然后才能根据他的角色来访问服务资源。

I want the user to log on to the client web app using forms authentication, authenticated by the wcf service, and then to be able to access service resources based on his roles.

到目前为止,我已经成功地登录使用System.Web.ApplicationServices.AuthenticationService虽然我一直没能得到IsLoggedIn服务方法返回true。但是,客户端Web应用程序不识别该用户已登录。

So far I have managed to log on using System.Web.ApplicationServices.AuthenticationService although I haven't been able to get the IsLoggedIn service method to return true. However, the client web app does recognise that the user has logged in.

此外,我已经能够创建识别用户在OperationContext.Current.ServiceSecurityContext.PrimaryIdentity一个虚拟的服务,我认为这是在记录在它被识别用户,但事实证明,它实际上是ServiceClient .ClientCredentials.UserName它能够识别。我怎样才能通过登录的用户到WCF服务?

Further, I have been able to create a dummy service that recognises the user in OperationContext.Current.ServiceSecurityContext.PrimaryIdentity and I thought that it was the logged in user that it was recognising but it turns out that it is actually the ServiceClient.ClientCredentials.UserName that it recognises. How can I pass through the details of the logged in user to the WCF service?

我可以设置为ClientCredentials.UserName登录的用户,但我不能想办法来获得密码。

I could set the ClientCredentials.UserName to the logged on user but I can't think of a way to get the password.

我使用完全错误的做法在这里或在那里,我失去了一些东西?任何意见将是AP preciated。

Am I using completely the wrong approach here or is there something that I am missing? Any advice would be appreciated.

这是我的绑定配置:

  <wsHttpBinding>
    <binding name="wsHttp">  
      <security mode="Message">  
        <message clientCredentialType="UserName"  
          negotiateServiceCredential="false"  
          establishSecurityContext="false"/>  
      </security> 
    </binding> 
  </wsHttpBinding>

谢谢,
伊恩

Thanks, Iain

推荐答案

我一直试图做在SharePoint类似的事情。我已经能够拿出最好的解决办法是:

I've been trying to do something similar in SharePoint. The best solution I've been able to come up with is:

 using (ChannelFactory<IMyContract> requestChannelFactory = new ChannelFactory<IMyContract>(binding, new EndpointAddress(endPointURL)))
 {
     provider = requestChannelFactory.CreateChannel();
     using (HostingEnvironment.Impersonate())
     {
         remoteData = provider.GetData();
     }
 }

这试图验证我以DOMAIN \\ SERVER $可惜我还没有找到一种方法来拉客户端凭据出来的HttpContext,并将它们鞋拔子到requestChannelFactory.Credentials.Windows.ClientCredential。我是pretty确保它无法做到的。另一种方法似乎是硬编码的用户​​名/密码或使用证书身份验证。这或允许匿名身份验证这是不是我的选择。

This tries to authenticate me as DOMAIN\SERVER$ but unfortunately I haven't found a way to pull the client credentials out of HttpContext and shoehorn them into requestChannelFactory.Credentials.Windows.ClientCredential. I'm pretty sure it can't be done. The alternative seems to be hardcoding the username/password or using certificate authentication. That or allowing anonymous authentication which is not an option for me.

这篇关于如何我通过登录从ASP.Net Web应用程序用户的详细情况WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆