SharePoint [debug, diagnostics error series]-use the code to obtain the correlationid of the current request

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.