Click here to Skip to main content
15,917,642 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
Response.Cookies["backgroundcolor"].Value = "Red";
            Response.Write(Request.Cookies["backgroundcolor"].Value);
            HttpCookie mycookie = new HttpCookie("cookie1");
            mycookie.Value = "some cookie value";
            mycookie.Expires = DateTime.Now.AddDays(100);
            Response.Cookies.Add(mycookie);
            Response.Cookies["mycookiename"].Value= "mycookievalue";
            Response.Cookies["mycookiename"].Expires = DateTime.Now.AddMinutes(15);
            Response.Cookies["visitordata"]["firstname"] = "select login from registerform where registerform.id='" + Id + "'";
            Response.Cookies["visitordata"]["lastvisit"] = DateTime.Now.ToString();
            if (Request.Cookies["mycookiename"] != null)
               mycookievalue = Request.Cookies["mycookiename"].Value;
pls check wat mistk in tis code
Posted
Updated 4-Jun-10 20:00pm
v2
Comments
Smithers-Jones 4-Jun-10 8:20am    
Reason for my vote of 1
No. This site is not a free code-correction-service. If you have a proper question, then ask, but don't post requests for correction in this demanding tone!
Henry Minute 4-Jun-10 8:31am    
Reason for my vote of 1
insufficient information for a proper question
Sandeep Mewara 4-Jun-10 8:44am    
Reason for my vote of 1
Same goes here as the earlier one! too demanding!... you need to learn how to ask for help first and then post your queries.

1 solution

mehalanandu wrote:
correct this code




C#
// Possible chance of null reference error. You should make a null check
Response.Cookies["backgroundcolor"].Value = "Red";
Response.Write(Request.Cookies["backgroundcolor"].Value);


HttpCookie mycookie = new HttpCookie("cookie1");
mycookie.Value = "some cookie value";


//100 days is too much for a cookie to expire
mycookie.Expires = DateTime.Now.AddDays(100);
Response.Cookies.Add(mycookie);


//Possible chance of null reference error
Response.Cookies["mycookiename"].Value = "mycookievalue";
Response.Cookies["mycookiename"].Expires = DateTime.Now.AddMinutes(15);


//This is not correct. Load the firstname from database, you are
// storing the query itself. ASP.NET
//is not going to execute this query for you.
//Sql Injection prone, use parameterized query
// Variable "Id" is not defined, from where this Id is coming??
Response.Cookies["visitordata"]["firstname"] =
  "select login from registerform where registerform.id='" + Id
 + "'";


Response.Cookies["visitordata"]["lastvisit"] = DateTime.Now.ToString();
if (Request.Cookies["mycookiename"] != null)


 //mycookievalue is undefined, you should create a string variable for this
 mycookievalue = Request.Cookies["mycookiename"].Value;
 
Share this answer
 
v2
Comments
mehalanandu 7-Jun-10 3:15am    
thank u ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900