Search code examples
asp.netiisetw

How to access the ASP.NET / IIS ContextId


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.


Solution

  • 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