How to get the Correlation ID of the current request in SharePoint

SharePoint generates for each request a random GUID which correlates all log messages in the ULS log which are printed during the current request. The Correlation ID is also printed to error pages. If you want more information about an error page you can use the Correlation ID to find the right log messages in the ULS log.

Recently I wanted to get the current request’s Correlation ID to share it with an external webservice to have the same correlation ID in all depending systems.

You can add following code to your ASP page to get the Correlation ID.