Tutorial on Cookies in asp.net

InfoPath alternatives for form designing SharePoint

Here we will discuss what is a cookie, as well as the types of cookies available in asp.net. You can also check Difference between cookie and session in asp.net.

– A cookie can be defined as small amount of memory used by the web server within the client system.

– The cookie are requested to maintain personal information of the client. Information like user name, no of visits, last visited date etc are get stored.

There are 2 types of cookies:
1. Inmemory cookie
2. Persistant cookie

Inmemory Cookie:
– When the cookie is maintained within browser process memory then it is called as inmemory cookie. This is very much temporary which will be erased when the browser is closed.

Create cookie:
HttpCookie obj = new HttpCookie(“nameofcookie”);
obj.Value = “100”;
Response.AppendCookie(obj); //Here cookie will be send to the browser.

Reading cookie:
HttpCookie obj;
obj = Request.Cookies[“nameofcookie”];
if(obj !=null)
{
string value = obj.Value; //This will return the value.
}

Persistent cookie:
– When the browser maintains cookie on to harddisk memory then it is called as persistant cookie.
– This will have a life time, when the cookie will earse.

Create cookie:
HttpCookie obj = new HttpCookie(“nameofcookie”);
obj.Value = “100”;
obj.Expires.AddDays(5);//Cookie will expire after 5 days
Response.AppendCookie(obj);

Reading cookie:
HttpCookie obj;
obj = Request.Cookies[“nameofcookie”];
if(obj !=null)
{
string value = obj.Value; //This will return the value.
}

Similar SharePoint 2013 Tutorials


About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply