与登录用户名ELMAH为WCF Web服务 [英] Logging username with Elmah for WCF Webservices
问题描述
我们正在使用的方法描述<一个href=\"http://stackoverflow.com/questions/895901/exception-logging-for-wcf-services-using-elmah/906494#906494\">here登录我们的web服务与错误ELMAH。而这种实际工作,但可悲的是beeing登录的用户名是空的。
We are using the approach described here to log our webservice errors with Elmah. And this actually works, but sadly the username beeing logged is empty.
我们做了一些调试,发现,记录中的ErrorHandler错误时, HttpContext.Current.User
具有正确的用户集。
We did some debugging and found, that when logging the error in the ErrorHandler the HttpContext.Current.User
has the correct User set.
我们也试过:
HttpContext context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(pError, context));
和
ErrorLog.GetDefault(null).Log(new Error(pError));
但没有成功。
对我们如何才能使ELMAH登录的用户名任何想法?
Any ideas on how we can make Elmah log the username?
在阿里纳斯,web服务中直接记录错误时,用户名如预期记录。但是,采取这种方式是不是很干。
On a sidenote, when logging the error directly within the Webservice, the username is logged as expected. But taking this approach is not very DRY.
推荐答案
ELMAH采取用户从 Thread.CurrentPrincipal.Identity.Name
,而不是从 HttpContext.Current.User
。
Elmah take the user from Thread.CurrentPrincipal.Identity.Name
and not from HttpContext.Current.User
.
由于ins't可以方便地将自定义数据添加到ELMAH,我会建议重新编译code,并调用HttpContext.Current.User来代替。
Since there ins't a convenient way to add custom data to Elmah, I would suggest recompiling the code, and calling HttpContext.Current.User instead.
这篇关于与登录用户名ELMAH为WCF Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!