Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WCF服务上使用Windows身份验证访问服务器端的用户名?_C#_Wcf_Silverlight_Wcf Ria Services_Windows Authentication - Fatal编程技术网

C# 如何在WCF服务上使用Windows身份验证访问服务器端的用户名?

C# 如何在WCF服务上使用Windows身份验证访问服务器端的用户名?,c#,wcf,silverlight,wcf-ria-services,windows-authentication,C#,Wcf,Silverlight,Wcf Ria Services,Windows Authentication,我有一个Silverlight应用程序,带有使用Windows身份验证的WCF服务。 我的用户得到了正确的身份验证。我可以在客户端访问他们的用户名和角色。 但我如何在服务器端做同样的事情呢? 我试过这个 ServiceSecurityContext.Current.WindowsIdentity 及 这是我在stackoverflow上发现的一个类似问题的答案,但它没有编译。 我收到“ServiceSecurityContext不包含当前定义”异常 那么如何让用户在服务器端呢 public s

我有一个Silverlight应用程序,带有使用Windows身份验证的WCF服务。 我的用户得到了正确的身份验证。我可以在客户端访问他们的用户名和角色。 但我如何在服务器端做同样的事情呢? 我试过这个

ServiceSecurityContext.Current.WindowsIdentity

这是我在stackoverflow上发现的一个类似问题的答案,但它没有编译。 我收到“ServiceSecurityContext不包含当前定义”异常

那么如何让用户在服务器端呢

public static string GetUserIdentity()
{
   return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
}
OperationContext位于System.ServiceModel命名空间中

OperationContext位于System.ServiceModel命名空间中。

请重试

HttpContext.Current.User;
希望这有帮助

试试看

HttpContext.Current.User;

希望这有帮助

这只在服务设置为ASP.NET兼容模式时才起作用。真的吗?这不是从请求头中获取用户名吗?根据:HttpContext:Current,从WCF服务中访问时始终为空。请改用RequestContext。。。除非您的服务被同一篇文章中的ASP.NET兼容性所修饰:WCF应用程序需要HTTP管道传统上提供的功能,应该考虑使用WCF等价物,它是主机和传输无关的:操作上下文,而不是HTTP语境。我的wcfService与silverlight web主机是在同一个项目中创建的,因此我认为它已自动设置为ASP.NET兼容模式。这仅在该服务已设置为ASP.NET兼容模式时有效。真的吗?这不是从请求头中获取用户名吗?根据:HttpContext:Current,从WCF服务中访问时始终为空。请改用RequestContext。。。除非您的服务被同一篇文章中的ASP.NET兼容性所修饰:WCF应用程序需要HTTP管道传统上提供的功能,应该考虑使用WCF等价物,它是主机和传输无关的:操作上下文,而不是HTTP语境。我的wcfService与silverlight web主机是在同一个项目中创建的,因此我估计它会自动设置为ASP.NET兼容模式