Friday 30 April 2021

How to Use Cookies in Asp.Net Core

 Hello Friends,  

In this article, I will explain how to Use Cookies in  ASP.NET CORE .

1. Let me show you how to Implement the Cookie in an ASP.NET Core application.


As for configuring the behavior of cookies globally, you can do it in the Startup.
public void ConfigureServices(IServiceCollection services)
    services.Configure<CookiePolicyOptions>(options =>
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;
        options.HttpOnly = HttpOnlyPolicy.Always;
        options.Secure = CookieSecurePolicy.Always;
        // you can add more options here and they will be applied to all cookies (middleware and manually created cookies)


2. CookieOptions

There are different cookie options available. It extends the cookie behavior in the browser.
Domain - The domain you want to associate with a cookie
Path - Cookie Path
Expires - The expiration date and time of the cookie
HttpOnly - Gets or sets a value that indicates whether a cookie is accessible by client-side script or not.
Secure - Transmit the cookie using Secure Sockets Layer (SSL) that is, over HTTPS only.  

Happy programming!!
Don’t forget to leave your feedback and comments below!
Sujeet Bhujbal


  1. This post is so interactive and informative.keep update more information...
    dot net training in Tambaram
    Dot net training in Chennai

  2. What will happen if my Google setting is Cookies Are Disabled? Will it affect the functionality of Asp.Net Core? Law Essay Writing Services

  3. The intricacies of website designing and development is crucial in today's digital landscape. This insightful guide on utilizing cookies in ASP.NET Core provides valuable knowledge for developers seeking to enhance user experience and functionality. A must-read for those navigating the world of web development.