如何访问 ASP.NET/IIS ContextId

发布于 2024-12-09 02:25:57 字数 174 浏览 1 评论 0原文

我在事件日志中多次看到给定 ASP.NET 请求的“ContextId”。我最近开始研究 ASP.NET 推出的 ETW 事件,并希望在我自己触发的事件中重用此 ContextID。

我该怎么做?

System.Threading.Thread.CurrentContext 似乎没有它。始终是 0。

I've seen way too many times in my event logs this "ContextId" for a given ASP.NET request. I've recently started looking into ETW events that are pushed out by ASP.NET, and want to re-use this ContextID in my own events that I fire.

How can I do this?

System.Threading.Thread.CurrentContext doesn't seem to have it. It's always 0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绮烟 2024-12-16 02:25:57

这是一个记录很少的功能,但是你可以得到它。

它位于 HttpWorkerRequest RequestTraceIdentifier 属性上。

http://msdn.microsoft.com/en-us /library/system.web.httpworkerrequest.requesttraceidentifier.aspx

This is a poorly documented feature, but yes you can get it.

It sits on the HttpWorkerRequest RequestTraceIdentifier property.

http://msdn.microsoft.com/en-us/library/system.web.httpworkerrequest.requesttraceidentifier.aspx

一杯敬自由 2024-12-16 02:25:57

您可以从 HttpWorkerRequest.RequestTraceIdentifier 属性获取它。请注意,显然您需要启用 IIS ETW(Windows 事件跟踪)功能,否则此属性将为 Guid.Empty。以下是如何从HttpContext获取它:

var serviceProvider = (IServiceProvider)HttpContext.Current;
var workerReqest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
var requestId = workerReqest.RequestTraceIdentifier;

参考:https://github.com/serilog/serilog/commit/b289dbcde3e0f7366d90daf66e00c94f4cc58de3#diff-4934d624fc1d467b08411d520972e840R48

You can get it from the HttpWorkerRequest.RequestTraceIdentifier property. Note that obviously you need to have the IIS ETW (Event Tracing for Windows) feature enabled or this property will be Guid.Empty. The following is how to get it from HttpContext:

var serviceProvider = (IServiceProvider)HttpContext.Current;
var workerReqest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
var requestId = workerReqest.RequestTraceIdentifier;

Reference: https://github.com/serilog/serilog/commit/b289dbcde3e0f7366d90daf66e00c94f4cc58de3#diff-4934d624fc1d467b08411d520972e840R48

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文