1- using eCommerce . Helpers . Logging ;
2- using System ;
3- using System . Security . Cryptography ;
4- using System . Text ;
5- using System . Web ;
6-
7- namespace eCommerce . WebService . App_Start
8- {
9- public class WebRequestCorrelationIdentifier : IRequestCorrelationIdentifier
10- {
11- public string CorrelationID { get ; private set ; }
12-
13- public WebRequestCorrelationIdentifier ( )
14- {
15- /* #Customise your correlation ID here
16- * More request identification variables you add easier
17- * it's going to be to find the relevant W3C request when you hash it
18- *
19- * Below is just an example of variables and hash algorithm that you can use:
20- */
21- string rawCorrelationID = string . Join ( "_" ,
22- HttpContext . Current . Request . ServerVariables [ "REMOTE_ADDR" ] ,
23- HttpContext . Current . Request . Params [ "LOGON_USER" ] ,
24- HttpContext . Current . Request . UserAgent . ToString ( ) ,
25- HttpContext . Current . Request . Path ,
26- DateTime . Now . ToString ( "dd/MM/yyyy HH:mm:ss" )
27- ) ;
28-
29- StringBuilder hashBuilder = new StringBuilder ( ) ;
30- using ( MD5 md5 = MD5 . Create ( ) )
31- {
32- byte [ ] hash = md5 . ComputeHash ( Encoding . UTF8 . GetBytes ( rawCorrelationID ) ) ;
33- for ( int i = 0 ; i < hash . Length ; i ++ )
34- hashBuilder . Append ( hash [ i ] . ToString ( "X2" ) ) ;
35- }
36-
37- this . CorrelationID = hashBuilder . ToString ( ) ;
38- }
39- }
1+ using eCommerce . Helpers . Logging ;
2+ using System ;
3+ using System . Security . Cryptography ;
4+ using System . Text ;
5+ using System . Web ;
6+
7+ namespace eCommerce . WebService . App_Start
8+ {
9+ public class W3CWebRequestCorrelationIdentifier : IRequestCorrelationIdentifier
10+ {
11+ public string CorrelationID { get ; private set ; }
12+
13+ public W3CWebRequestCorrelationIdentifier ( )
14+ {
15+ /* #Customise your correlation ID here
16+ * More request identification variables you add easier
17+ * it's going to be to find the relevant W3C request when you hash it
18+ *
19+ * Below is just an example of variables and hash algorithm that you can use:
20+ */
21+ string rawCorrelationID = string . Join ( "_" ,
22+ HttpContext . Current . Request . ServerVariables [ "REMOTE_ADDR" ] ,
23+ HttpContext . Current . Request . Params [ "LOGON_USER" ] ,
24+ HttpContext . Current . Request . UserAgent != null ?
25+ HttpContext . Current . Request . UserAgent . ToString ( ) . Replace ( " " , "+" ) : "-" ,
26+ HttpContext . Current . Request . Path ,
27+ HttpContext . Current . Request . QueryString . ToString ( ) ?? "-" ,
28+ new DateTime ( HttpContext . Current . Timestamp . Ticks ) . ToUniversalTime ( ) . ToString ( "yyyy-MM-dd HH:mm:ss" )
29+ ) ;
30+
31+ StringBuilder hashBuilder = new StringBuilder ( ) ;
32+ using ( MD5 md5 = MD5 . Create ( ) )
33+ {
34+ byte [ ] hash = md5 . ComputeHash ( Encoding . UTF8 . GetBytes ( rawCorrelationID ) ) ;
35+ for ( int i = 0 ; i < hash . Length ; i ++ )
36+ hashBuilder . Append ( hash [ i ] . ToString ( "X2" ) ) ;
37+ }
38+
39+ this . CorrelationID = hashBuilder . ToString ( ) ;
40+ }
41+ }
4042}
0 commit comments