Login Register
Code2night
  • Home
  • Guest Posts
  • Blog Archive
  • Tutorial
  • Languages
    • Angular
    • C
    • c#
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • Security
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
    • SEO Analyzer
  1. Home
  2. Blog
  3. HttpCookies Issue with Asp.Net Core 3.1

HttpCookies Issue with Asp.Net Core 3.1

Date- Jun 07,2022

6266

AspNet core 31 Aspnet core 21

HttpCookies in Asp.Net Core 2.1

So, for a Asp.Net core 2.1 web application if you want to use HttpCookies you have to add this in your startup.cs file inside ConfigureServices method.

   services.Configure<CookiePolicyOptions>(options =>
          {
              options.CheckConsentNeeded = context => false;
              options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.None;
           });

After adding this, you can save your httpcookies like this

  CookieOptions option = new CookieOptions
            {
                Expires = DateTime.Now.AddDays(1)
            };
            Response.Cookies.Append("key", "value", option);

For getting the saved cookie value in your project you can do this

 var cookies = Request.Cookies["key"];

So, you can set your own keyname and use that to get your cookie value in Asp.net core 2.1. However you will notice if you try the same in Asp.Net core 3.1 , you will not be able to get your cookie value as values does not get saved used this method.

HttpCookie in Asp.net Core 3.1

So, for a Asp.Net core 2.1 web application if you want to use HttpCookies you have to add this in your startup.cs file inside ConfigureServices method.

 services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan = TimeSpan.FromDays(1);

                options.SlidingExpiration = true;
            });

For saving the HttpCookie you can use the same method like Asp.net core 2.1 .

   CookieOptions option = new CookieOptions
            {
                Expires = DateTime.Now.AddDays(1)
            };
            Response.Cookies.Append("key", "value", option);

For getting the saved cookie value also we will use same method like we did for Asp.Net core 2.1

 var cookies = Request.Cookies["key"];

So this is how you can fix issue with HttpCookies when you upgrade your application from Asp.net core 2.1 to Asp.net Core 3.1.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Get Mime Type for any extension in Asp.Net
May 15, 2023
Get random number in asp.net C#
Dec 23, 2023
Linkedin Sign In using LinkedinLogin Nuget package in Asp-Net MVC
Apr 14, 2023
Using Firebase Database in Asp.Net
Sep 22, 2022

Comments

Contents

More in ASP.NET Core

  • How to Encrypt and Decrypt Password in Asp.Net 25930 views
  • Exception Handling Asp.Net Core 20708 views
  • HTTP Error 500.31 Failed to load ASP NET Core runtime 20191 views
  • How to implement Paypal in Asp.Net Core 19602 views
  • Task Scheduler in Asp.Net core 17493 views
View all ASP.NET Core posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
  • SEO Analyzer
By Language
  • Angular
  • C
  • c#
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page