5
Answers

Cookie

sunakshi saxena

sunakshi saxena

12y
1.8k
1
How we can retrieve cookies stored in system, I need a asp.net program to retrieve existing  cookies from system and also when we enter information like user name password in system it will be saved in system and later if i want to retrieve. it could be retrieve. reply as soon as possible.
Answers (5)
0
0
Senthilkumar

Senthilkumar

NA 15.2k 2.4m 12y
Hi Sunakshi,



In the ASP.Net server side,


int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;


MyCookieColl = Request.Cookies;


// Capture all cookie names into a string array.
String[] arr1 = MyCookieColl.AllKeys;


// Grab individual cookie objects by cookie name.
for (loop1 = 0; loop1 < arr1.Length; loop1++) 
{
   MyCookie = MyCookieColl[arr1[loop1]];
   Response.Write("Cookie: " + MyCookie.Name + "<br>");
   Response.Write ("Secure:" + MyCookie.Secure + "<br>");


   //Grab all values for single cookie into an object array.
   String[] arr2 = MyCookie.Values.AllKeys;


   //Loop through cookie Value collection and print all values.
   for (loop2 = 0; loop2 < arr2.Length; loop2++) 
   {
      Response.Write("Value" + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
   }
}


Reading all the cookies in client side javascript,


<html>
<head>
<script type="text/javascript">
<!--
function ReadCookie()
{
   var allcookies = document.cookie;
   alert("All Cookies : " + allcookies );


   // Get all the cookies pairs in an array
   cookiearray  = allcookies.split(';');


   // Now take key value pair out of this array
   for(var i=0; i<cookiearray.length; i++){
      name = cookiearray[i].split('=')[0];
      value = cookiearray[i].split('=')[1];
      alert("Key is : " + name + " and Value is : " + value);
   }
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
<input type="button" value="Get Cookie" onclick="ReadCookie()"/>
</form>
</body>
</html>


For more info:
http://www.tutorialspoint.com/javascript/javascript_cookies.htm
http://stackoverflow.com/questions/8315251/how-can-i-get-cookies-from-httpclienthandler-cookiecontainer
http://www.electrictoolbox.com/javascript-get-all-cookies/



0
Abhimanyu K Vatsa

Abhimanyu K Vatsa

NA 52.1k 12.4m 12y
Use following after setup your complete page having grdCookies.

ArrayList colCookies = new ArrayList();
        for (int i = 0; i < Request.Cookies.Count; i++)
            colCookies.Add(Request.Cookies[i]);
        grdCookies.DataSource = colCookies;
        grdCookies.DataBind();
0
sunakshi saxena

sunakshi saxena

NA 54 60k 12y
I want to retrieve already existing cookies in browser. not that which i am entering statically by text boxes now.
0
Muralidharan Deenathayalan

Muralidharan Deenathayalan

NA 21.9k 1.5m 12y