2

How can i make it so my c# application gets cookie data when it uses http so it can be stored for the next page.

For example, it logs in.. Then it enters another webpage which requires the same data received from when logging in.

Here is the code:

Code!

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Oliver Kucharzewski
  • 2,523
  • 4
  • 27
  • 51

3 Answers3

1


Here are a few examples of creating and retrieving cookies.

Automatic Cookie Handling C#/.NET HttpWebRequest+HttpWebResponse

http://msdn.microsoft.com/en-us/library/dd920298(v=vs.95).aspx

It's advisable to avoid storing sensitive data in cookies. If you are, then at least encrypt it using something like AesCryptoServiceProvider: http://msdn.microsoft.com/en-us/library/system.security.cryptography.aescryptoserviceprovider.aspx

hopefully this helps.

Community
  • 1
  • 1
Nickz
  • 1,880
  • 17
  • 35
  • Hey there, i tried the cookiejar thing in the first link, i keep retrieving 0 as a value when printing to console. Which means i get 0 cookies. – Oliver Kucharzewski Feb 23 '12 at 06:17
0

Add Cookie :

HttpCookie aCookie = new HttpCookie("userName");
aCookie.Value = "pranay";
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);

Retrieve Cookie :

if(Request.Cookies["userName"] != null)
{
    HttpCookie aCookie = Request.Cookies["userName"];
    Label1.Text = Server.HtmlEncode(aCookie.Value);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0

Have you thought about using querystring data?

yourUrl.aspx?username=mrWonderful&password=myPass

and then parse that login data on the next page.

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Induster
  • 733
  • 1
  • 6
  • 15
  • QueryStrings are great, but passing sensitive data like a username or passwords in a query string well your making it easier for malicious users to get access to your websites user accounts. – Nickz Feb 23 '12 at 06:12