How to create cookie and read cookie in asp.net using c#

This article show you how to create cookie and read cookie in asp.net using c#.

Code : 

  Create cookie 
   
    // create cookie
    //HttpCookie cookie= new HttpCookie("cookie_name", "cookie_value");
    HttpCookie cookie = new HttpCookie(("Security"), "ok");
    //set expire time for cookie
    cookie.Expires = DateTime.Now.AddMinutes(30);
    Response.Cookies.Add(cookie);

  Read cookie :                            

    // Read the cookie 
    // check whether cookie has been set or not yet
    //Request.Cookies["cookie_name"]
    if (Request.Cookies["Security"] != null)
   {    
        //write your code here
         Response.Redirect("Default.aspx");
    }

Done...
How to create cookie and read cookie in asp.net using c# How to create cookie and read cookie in asp.net using c# Reviewed by BeiLover on 12:13 PM Rating: 5

1 comment:

Powered by Blogger.