Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.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应用程序_C#_Asp.net_Wcf_Security_Interop - Fatal编程技术网

C# 将经过身份验证的用户发送到WCF应用程序

C# 将经过身份验证的用户发送到WCF应用程序,c#,asp.net,wcf,security,interop,C#,Asp.net,Wcf,Security,Interop,我有2份申请;一个是ASP.NET 3.5 Ajax应用程序(客户端),另一个是WCF Web应用程序(后端) 这些应用程序通过IIS 7部署在单独的Windows Server 2008中。后端应用程序启用了net.tcp和http绑定;一些服务在netTcpBinding下公开,其他服务在basicHttpBinding下公开;绑定没有配置任何安全性 客户端应用程序使用FormsAuthentication对用户进行身份验证。netTcpBinding下的所有服务都在客户端应用程序中使用。在

我有2份申请;一个是ASP.NET 3.5 Ajax应用程序(客户端),另一个是WCF Web应用程序(后端)

这些应用程序通过IIS 7部署在单独的Windows Server 2008中。后端应用程序启用了net.tcp和http绑定;一些服务在netTcpBinding下公开,其他服务在basicHttpBinding下公开;绑定没有配置任何安全性


客户端应用程序使用FormsAuthentication对用户进行身份验证。netTcpBinding下的所有服务都在客户端应用程序中使用。在后端,我需要知道哪个用户调用服务来执行一些审计任务。这是可能的吗?

< P>如果您实际上不想在后端服务上实现安全性,只想能够审核用户身份(即您实际上信任谁向您发送该身份信息),您可以考虑通过每个请求通过自定义标题传递身份信息。p> 要做到这一点,您可以创建一个自定义文件,该文件通过在BeforeSendRequest实现中的HttpContext.current.User.Name之类的内容从当前ASP.NET上下文中提取信息来添加标题。要将IClientMessageInspector附加到客户端代理,只需创建一个客户端代理,然后通过配置将其添加到端点(检查示例代码)

以下是BeginSendRequest实现的外观:

public void BeginSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
   string currentContextUserName = HttpContext.Current.User.Identity.Name;

   MessageHeader userNameHeader = MessageHeader.CreateHeader("Username", "urn:my-custom-namespace", currentContextUserName);

   request.Headers.Add(userNameHeader);
}

在服务器端,您可以通过在其中实现审计并执行审计来考虑通用审计。或者,您可以在可能希望通过属性使用标题的方法中“手动”检索标题