Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

Looking for a C# demo that reads and writes to a cookie

I would like to download a C# program which writes to a cookie then also reads that cookie and its value, the second time.

Thanks.
0
newbieweb
Asked:
newbieweb
3 Solutions
 
Miguel OzSoftware EngineerCommented:
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello,

Writing Cookies
Response.Cookies["userName"].Value = "patrick";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

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

Reading Cookies:
if(Request.Cookies["userName"] != null)
    Label1.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);

if(Request.Cookies["userName"] != null)
{
    HttpCookie aCookie = Request.Cookies["userName"];
    Label1.Text = Server.HtmlEncode(aCookie.Value);
}
Below link will give you full detailed information about cookies
http://msdn.microsoft.com/en-us/library/ms178194.aspx
0
 
sonawanekiranCommented:
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now