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 a web application and website in Asp.Net.

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

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

There are 2 types of cookies:
1. In memory cookie
2. Persistent cookie

In memory Cookie:
– When the cookie is maintained within the browser process memory then it is called as an in-memory 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.
}

You can also check my previous article on:

– type is undefined script resource and in ajax control toolkit


– What is the role of ScriptManager in Ajax?

– How to make scaling animation effect using AnimationExtender Control in asp.net


You May Also like the Following SharePoint Online 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