In sharepoint2010, each request has its own correlation ID. When tracking or debugging, we use ULS to find specific information (such as error information ), for details about how to use correlation ID, see this article (SharePoint Study Notes-Debug -- Correlation ID). Here we will use code to obtain the correlation ID of the current request.
First, create a new class in our project: myspcorrelationid. cs. This class has a method getcurrentcorrelationtoken (), and the Code of myspcorrelationid. CS is as follows:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. runtime. interopservices;
Namespace copylistcontent
{
Public class myspcorrelationid
{
[Dllimport ("advapi32.dll")]
Public static extern uint eventactivityidcontrol (uint controlcode, ref guid activityid );
Public const uint event_activity_ctrl_get_id = 1;
Public static guid getcurrentcorrelationtoken ()
{
Guid G = guid. empty;
Eventactivityidcontrol (event_activity_ctrl_get_id, ref G );
Return g;
}
}
}
Create a Viusal webpart and put a button and a label
Write in the button's Click Event
Protected void btngetcorrelation_click (Object sender, eventargs E)
{
Lblcurcorrelation. Text = myspcorrelationid. getcurrentcorrelationtoken (). tostring ();
}
Deploy this webpart. click the button to obtain the correlation ID of the current request. For example:
Of course, in practice, you usually write this code to any location where you want to obtain the correlation ID (eg: Try/catch, event, Referer ), then write or output the correlation ID to a location that the user can easily obtain (eg: Label, alert .... if you can train your user so that he can pass the correlation ID you obtained in this code along with their operation records to you, you can locate and solve problems more conveniently and quickly.