The cookie value is displayed on the Response surface, and the token is as follows: Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
// Retrieve the value in the cookie Scott 20080610
If (Request. Cookies. Count > 0 )
{
Httpcookiecollection hcccookie= NewHttpcookiecollection ();
//Obtain the cookie from the receiver.
Hcccookie=Request. Cookies;
// Get all keys
String [] Sarr = Hcccookie. allkeys;
Response. Write ( " Hcccookie. allkeys data volume " + Sarr. Length + " <Br> " );
Httpcookie HC;
Int I = 1 ;
Foreach ( String Scookie In Request. Cookies. allkeys)
{
Response. Write ( " The " + I + " Value: <br> " );
HC = Hcccookie [scookie];
Response. Write (convertutf8 (scookie) + " Whether the sub-key is included: " + HC. haskeys + " <Br> " );
// Determines whether a Shard has a sub-key. If yes, the values are obtained by following the operator.
If (HC. haskeys)
{
Response. Write ( " The sub-key value is: <br> " );
Foreach ( String Svar In HC. values)
{
String Cookiesubkey = Convertutf8 (svar );
String Cookiesubvalue = Convertutf8 (HC [svar]);
Response. Write (cookiesubkey + " : " + Cookiesubvalue + " <Br> " );
}
}
// When no sub-key exists, the value is obtained directly.
Else
{
Response. Write (convertutf8 (scookie) + " Value: " + Convertutf8 (HC. value) + " <Br> " );
}
I++;
}
}
}
/// <Summary>
/// Convert content into utf8
/// </Summary>
/// <Param name = "asvalue"> </param>
/// <Returns> </returns>
Private String Convertutf8 ( String Asvalue)
{
System. Text. Encoding encvalue = System. Text. encoding. getencoding ( " UTF-8 " );
// Httputility: provides methods for encoding and decoding URLs when processing Web requests.
String Sreturn = Httputility. urldecode (asvalue, encvalue );
Return Sreturn;
}
}