【问题标题】:WCF Forms Based Authentication Via Web App - Passing Credentials通过 Web 应用程序基于 WCF 表单的身份验证 - 传递凭据
【发布时间】:2009-05-19 15:13:49
【问题描述】:

我有一个简单的 Web 服务,通过基于表单的身份验证来处理安全性。

WCFTestService.ServiceClient myService = new
          WCFTestService.ServiceClient();
myService.ClientCredentials.UserName.UserName = "user";
myService.ClientCredentials.UserName.Password = "secret";
lblResult.Text = myService.GetData(1231);
myService.Close();  

我正在通过网络应用程序访问它。所以我想做一次以上但为了安全/性能不必再做一次。我在想像下面这样的事情,但是当我使用 FormsAuthentication 时,这不起作用......

//Obtain the authenticated user's Identity and impersonate the original caller
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
  WCFTestService.ServiceClient myService2 = new WCFTestService.ServiceClient();
  lblResult.Text = "From Logged On Credentials"+myService2.GetData(1231);
  myService2.Close();
}

【问题讨论】:

    标签: asp.net wcf wcf-security


    【解决方案1】:

    您要做的是在您的客户端和您的服务之间建立一个“安全会话”。这是一个仅适用于 wsHttpBinding 的概念 - 因此,如果您不使用该特定绑定,它将不起作用。

    要建立安全会话,您需要在客户端和服务器的配置文件中设置一些特定的配置属性 - 您当然可以通过阅读文档找到这些设置(查找“建立安全上下文”)或查看 Michele Leroux Bustumante 的MSDN 上的优秀 WCF screencast on security fundamentals

    但实际上:我不建议您尝试使用安全会话。在正常情况下,使用 per-call 服务是首选方案,每次服务调用重新进行身份验证的开销确实可以忽略不计。

    马克

    【讨论】:

      猜你喜欢
      • 2010-11-22
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 2020-03-04
      相关资源
      最近更新 更多