NLog:记录在IIS中的WCF应用程序中调用应用程序的用户
我有以下场景:
已部署的 WCF 服务作为 Windows 托管服务运行。此 WCF 服务用于将特定事件记录到数据库 (NLog v2)。此服务使用 basicHttpBinding。
在 IIS 下部署的 Web 应用程序(不同的服务器)。应用程序池在 NETWORK SERVICE 凭据下运行。 Web 应用程序身份验证是 Windows 集成的(Active Directory 凭据)。
每当我从控制台应用程序调用 WCF 时,我都可以从 System.Threading.Thread.CurrentPrincipal.Identity.Name 获取用户身份;当我从 Web 应用程序调用它时,我希望获得 "DOMAIN\SERVER$"
作为线程标识名称(按预期发生)。
我的问题是:我想获取调用 Web 应用程序的用户。我已经尝试在 WCF 服务协定中设置 AspNetCompatibilityRequirements
属性,但是 ${asp-application}
、${aspnet-user-identity} NLog 中的
和 ${asp-request}
参数被读取为 null
。 Web 应用程序中的 HttpContext 正常,但未发送到 WCF。 NLog.Logger
类中有一个 Credentials
属性,但它是只读的。
有谁知道如何解决它?
I have the following scenario:
A deployed WCF service running as windows hosted service. This WCF service is used to log specific events to a database (NLog v2). This service uses basicHttpBinding.
A deployed web application (different server) under IIS. The Application pool runs under NETWORK SERVICE credentials. The web application authentication is Windows-integrated (Active Directory credentials).
Whenever I call the WCF from a console application I can get the user identity from System.Threading.Thread.CurrentPrincipal.Identity.Name
; when I call it from the web application I expect to get "DOMAIN\SERVER$"
as the thread identity name (which occurs as expected).
My problem is: I'd like to get the user who called the web application. I've already tried to set the AspNetCompatibilityRequirements
attribute in the WCF service contract, but the ${asp-application}
, ${aspnet-user-identity}
and ${asp-request}
parameters in NLog are read as null
. The HttpContext
in the web application is OK, but it is not being sent to the WCF. There's a Credentials
property in the NLog.Logger
class, but it's read-only.
Does anyone know how to solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能,您需要设置 impersonateCallerForAllOperations 属性
有关详细信息,请参阅 MSDN:http://msdn.microsoft.com/en-us/library/ms731306.aspx
Probably, you need to set impersonateCallerForAllOperations attribute
See MSDN for details: http://msdn.microsoft.com/en-us/library/ms731306.aspx
如果您可以从代码中获取用户,您可以这样做:
现在您可以在 nlog config1 中使用
${myUser}
If you could get the user from code, you could do this:
Now you could use
${myUser}
in your nlog config1