
September 12, 2025 08:02 by
Peter
Anyone interested in learning how to use the Asp.net core MVC application to save data in browser cookies should read this post. You can use the Asp.net Core MVC web application to develop a sample web application if you wish to put it into practice.

Let's begin.
In essence, a cookie is a tiny bit of information sent to the user's web browser by the server. It might be saved by the browser and sent back to the same server with a subsequent request. Usually, the browser uses it to determine whether two requests originated from the same browser.
Types of cookie
Persistent cookie
A cookie that has not to have expired time which is called a persistent cookie
Non-Persistent cookie
Cookie which has expired time is called a Non-persistent cookie
Adding cookie to the browser
First, add methods inside the Home controller. I have created an action method as CreateCookie and I have added key as DemoCookie. After that I have stored string value as Yogesh so we can store this value in the client browser
public IActionResult CreateCookie() {
string key = "DemoCookie:;
string value = Yogesh;
cookieOptions obj = new CookieOptions();
obj.Expires = DateTime.Now.AddDays(7);
Response.Cookie.Append(key, value, options);
return view();
}
To see the cookie which is added in the browser I am using Google Chrome.

Now we will see how to retrieve data from cookies, here I have created Action Method ReadData that is used to retrieve data from cookies.
public IActionResult Read Data() {
string key = "DemoCookie";
var CookieValue = Request.Cookies[key];
return View();
}

Now we will see how to delete data that is stored in cookies, here I have created the Action method Delete to perform the Delete operation on the cookie.
public IActionResult Delete() {
string key = "DemoCookie";
string value = DateTime.Now.ToString();
CookieOptions options = new CookieOptions();
options.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Append(key, value, options);
return View();
}
Summary
In this article, we have seen how to store data into cookies and retrieve and delete data from cookies. Hope you guys like it. Happy Coding!