{"id":14303,"date":"2023-10-30T06:57:06","date_gmt":"2023-10-30T06:57:06","guid":{"rendered":"https:\/\/positiwise.com\/blog\/?p=14303"},"modified":"2023-11-01T09:16:39","modified_gmt":"2023-11-01T09:16:39","slug":"how-to-use-cookies-in-asp-net-core","status":"publish","type":"post","link":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core","title":{"rendered":"How to Use Cookies in ASP.NET Core?"},"content":{"rendered":"\n<p><strong class=\"pw-highlight-text-color\"><em>Quick Overview:<\/em><\/strong><br>In this blog, you are going to discover the cookies fundamentals and the correct way to utilize them with the ASP.NET Core MVC project. With the information about cookie types, their pros and cons, and use cases, the blog moves to the cookie code blocks to implement. As a result, you will find yourself equipped with the knowledge to configure cookies in an ASP.NET Core web app, within a controller, and in a web API handler.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#A_Run-Through_NET_Core_vs_Nodejs\" >A Run-Through: .NET Core vs Node.js<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#NET_Core\" >.NET Core<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Pros_of_using_NET_Core\" >Pros of using .NET Core<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Nodejs\" >Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#A_Deep_Dive_into_NET_Core_vs_Nodejs\" >A Deep Dive into .NET Core vs. Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Processing_Approach_and_Performance\" >Processing Approach and Performance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Security\" >Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Scalability\" >Scalability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Platform_Adaptability\" >Platform Adaptability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Support_from_Community\" >Support from Community<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Comparison_Table_between_NET_Core_and_Nodejs\" >Comparison Table between .NET Core and Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Wrapping_Up_on_NET_Core_vs_Nodejs\" >Wrapping Up on .NET Core vs Node.js<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">Working With Cookie in ASP.NET Core<\/h2>\n\n\n\n<p>Cookies are considered integral to an application. They help in personalizing experiences and managing sessions and states. Due to this, businesses prefer ASP.NET Core web applications with cookies implementation.<\/p>\n\n\n\n<p>Therefore, as a <a href=\"https:\/\/positiwise.com\/hire-asp-net-developers\">.NET developer<\/a>, you should create a new ASP.NET Core web application with cookies functionality. To do so, you don\u2019t have to go anywhere else. In this blog, you can find everything, from cookies fundamentals to their implementation in an ASP.NET Core MVC project and an ASP.NET Core API application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are HTTP Cookies?<\/h2>\n\n\n\n<p>HTTP cookies are a piece of data consuming KBs of space during web connections. The web server exchanges this data type with the client browser and sometimes even stores it on the browsers. Nowadays, every website and web app uses cookies. Even when you visit a site, a message is displayed that &#8220;<strong>this site uses cookies.<\/strong>&#8220;<\/p>\n\n\n\n<p>Primarily, cookies contain user data, which helps to improve the experience. For example, if the cookies access the location, they will use this data to identify the nearest CDN server to boost performance and loading speed.<\/p>\n\n\n\n<p>In addition, the working of cookies depends on its type, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Session Cookies:<\/strong> The session cookies maintain the connection between a server and a client browser. These cookies are available for a temporary period until the session server-client session is not terminated.<\/li>\n\n\n\n<li><strong>Persistent Cookies:<\/strong> The persistent cookies get stored and are available for extended periods, sometimes until the user doesn&#8217;t delete them. The primary purpose of such cookies is to personalize the user experience.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The Pros and Cons of Using Cookies in Dotnet Core Applications<\/h2>\n\n\n\n<p>If implementing cookies provides several pros, it also comes with cons.<\/p>\n\n\n\n<p>The pros of cookies include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Easy sessions and state management.<\/li>\n\n\n\n<li>Helps in personalizing and improving the experience.<\/li>\n\n\n\n<li>Supports authentication and authorization.<\/li>\n\n\n\n<li>Optimizes sever-client communication.<\/li>\n\n\n\n<li>Helps to save resources and persistence sessions.<\/li>\n<\/ul>\n\n\n\n<p>The cons of cookies include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It can create security concerns if not used with proper security mechanisms.<\/li>\n\n\n\n<li>More network and processing resources are used.<\/li>\n\n\n\n<li>Cookies are easily exploited during XSS (Cross-Site Scripting) and CSRF (Cross-Site Request Forgery) attacks.<\/li>\n\n\n\n<li>They have smaller sizes, restricting the data to be stored in them.<\/li>\n\n\n\n<li>In some geographical areas, cookies are prohibited due to privacy concerns.<\/li>\n<\/ul>\n\n\n\n<p>To help you get the best-in-class implementation of cookies, you should always seek <a href=\"https:\/\/positiwise.com\/technologies\/dot-net-development\">.NET development services<\/a> from a trusted and experienced company. They can help you with proper security configurations and standard compliance, leading to eliminating cookies cons for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Use Case of Cookies in ASP.NET Core MVC Project<\/h2>\n\n\n\n<p>In the ASP.NET Core MVC project and ASP.NET Core Web API application, you can utilize cookies for the following purposes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Authenticating the user sessions and providing the permissions per the authorization policies, roles, and responsibilities.<\/li>\n\n\n\n<li>To store the user preferences for a particular website, such as theme, language, and more.<\/li>\n\n\n\n<li>To retain the products added to the cart. Most eCommerce stores use cookies, and even <a href=\"https:\/\/positiwise.com\/industry\/ecommerce-software-solutions\">eCommerce development<\/a> companies prefer it.<\/li>\n\n\n\n<li>To manage the sessions for multiple clients and associated requests.<\/li>\n\n\n\n<li>For tracking the user behavior and making an account of daily website visitors.<\/li>\n\n\n\n<li>To analyze user engagement and optimize marketing campaigns for better growth.<\/li>\n\n\n\n<li>To provide location-based services to a particular target audience.<\/li>\n<\/ul>\n\n\n\n<p>There are many more use cases of cookies in ASP.NET Core web applications, which top-notch companies, such as <a href=\"https:\/\/positiwise.com\">Positiwise Software Pvt Ltd<\/a>, can effortlessly fulfill.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How To Use Cookies in Asp.NET Core Web Application?<\/h2>\n\n\n\n<p>To understand the answer to the &#8220;How To Use Cookies in ASP.NET,&#8221; we will use the Visual Studio IDE 2019 or above version. Users always prefer the latest version because it provides all the required tools and supports significant frameworks.<\/p>\n\n\n\n<p>Once you complete the Visual Studio IDE installation, follow the procedure below in the provided order.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Open the Visual Studio IDE and left-click the &#8220;<strong>Create new Project<\/strong>&#8221; option.<\/p>\n\n\n\n<p><strong>Step 2:<\/strong> Choose the <strong>ASP.NET Core Web Application<\/strong> from the available templates. These are the pre-built projects with fundamental files and functionalities.<\/p>\n\n\n\n<p>Further, you need to fill in the project details. Also, to move further in the project creation, click on the <strong>Next\/Crete<\/strong> button.<\/p>\n\n\n\n<p><strong>Step 3:<\/strong> Provide your project details in the &#8220;<strong>Configure your new project<\/strong>&#8221; window. Here, you must provide the name and location where you want to save files.<\/p>\n\n\n\n<p><strong>Step 4:<\/strong> Now, you will view the &#8220;<strong>Create a New ASP.NET Core Web Application<\/strong>&#8221; window. Here, do the following configurations.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Choose <strong>ASP.NET Core 2.2<\/strong> and <strong>.NET Core<\/strong> for runtime from the drop-down list.<\/li>\n\n\n\n<li>Choose \u201c<strong>Web Application (Model-View-Controller)<\/strong>.<\/li>\n\n\n\n<li>Uncheck the \u201c<strong>Configure for HTTPS<\/strong>\u201d and \u201c<strong>Enable Docker Support<\/strong>\u201d options.<\/li>\n\n\n\n<li>Assure that \u201c<strong>No Authentication<\/strong>\u201d is selected.<\/li>\n<\/ul>\n\n\n\n<p><strong>Step 5: <\/strong>Lastly, hit on the <strong>Create<\/strong> button. As a result, you will have your <a href=\"https:\/\/positiwise.com\/blog\/introduction-asp-net-core-mvc\">ASP.NET Core MVC<\/a> project. <\/p>\n\n\n\n<p>Now, we will use this project to configure cookies-associated functions in the application. All the code blocks for major cookies functionality are in the further sections. We have divided the cookies implementation into read, write, delete, and access in the ASP.NET Core web app. Let&#8217;s have a look at all of them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">#1: Reading a Cookie<\/h3>\n\n\n\n<p>To read a cookie, you must configure the application to access Request.Cookies collection. To do so, implement the following code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string cookie = Request.Cookies&#91;\"Key\"];<\/code><\/pre>\n\n\n\n<p>In addition, you can also define when the cookie will expire by using the Append method with its overloaded version. It uses a CookieOptions class, which aids in defining the domain, expiration time, path, security policy, and HttpOnly property.&nbsp;<\/p>\n\n\n\n<p>All the mentioned properties specify the associated domain, cookie path, enabling access over HTTPS connection, cookie expiration time, and cookie availability to the server. You need to define all these properties similarly to the following snippet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CookieOptions option = new CookieOptions(); \noption.Expires = DateTime.Now.AddMilliseconds(10); \nResponse.Cookies.Append(key, value, option); <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#2: Writing a Cookie<\/h3>\n\n\n\n<p>Writing a cookie uses the same Append method, in which you have to define a key and a value to pertain to the Request object. To write a cookie, use the following syntax.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Response.Cookies.Append(somekey, somevalue);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#3: Deleting a Cookie<\/h3>\n\n\n\n<p>Along with reading and writing, deleting cookies is also necessary. It helps to remove the cookies from memory and free the space for further procedures. For it, you have to define the cookie delete method, similar to the following code block.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Response.Cookies.Delete(somekey);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#4: Accessing HttpContext<\/h3>\n\n\n\n<p>In the ASP.NET Core web application, you use HttpContext to access the cookie data. To implement this, you use the HttpContextAccessor class, which extends the functionality by providing the IHttpContextAccessor interface.<\/p>\n\n\n\n<p>To utilize this interface, it has to be registered with dependency injection. Otherwise, the application will not provide cookie access. With the below-provided code, you can enable a singleton service under the Startup class \u00e0 ConfigureServices method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public void ConfigureServices(IServiceCollection services)\n        {\n            services.AddSingleton&lt;IHttpContextAccessor,\n            HttpContextAccessor&gt;();\n            \/\/Other code\n        }<\/code><\/pre>\n\n\n\n<p>In addition, you can also define a reference to HttpContext. It will leverage you from the IHttpContextAccessor instance dependency injection. Moreover, you can access this instance using the HomeController, which gets created with every ASP.NET MVC project in Visual Studio IDE.<\/p>\n\n\n\n<p>By implementing the following code, the IHttpContextAccessor instance can be accessed in the HomeController.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class HomeController : Controller\n{\n  private readonly IHttpContextAccessor _httpContextAccessor;\n  public HomeController(IHttpContextAccessor httpContextAccessor)\n  {\n     this._httpContextAccessor = httpContextAccessor;\n  }   \n  \/\/Write your action methods here\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#5: Writing Cookie in Controller Method<\/h3>\n\n\n\n<p>To write cookies using the HomeController, the IActionResult Write method will be used. Under it, you need to define the CookieOptions like the below code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public IActionResult Write(string key, string value, bool isPersistent)\n  {\n       CookieOptions options = new CookieOptions();\n       if (isPersistent)\n           options.Expires = DateTime.Now.AddDays(1);\n       else\n           options.Expires = DateTime.Now.AddSeconds(10);\n       _httpContextAccessor.HttpContext.Response.Cookies.Append\n       (key, value, options);\n       return View(\"WriteCookie\");\n  }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#6: Reading Cookie in Controller Method<\/h3>\n\n\n\n<p>To read the cookie data, you must first implement the write code. Later, you can utilize the following code for viewing it using the controller.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public IActionResult Read(string key)\n  {\n       ViewBag.Data =\n       _httpContextAccessor.HttpContext.Request.Cookies&#91;key];\n       return View(\"ReadCookie\");\n  }<\/code><\/pre>\n\n\n\n<p>That&#8217;s how you use cookies in the ASP.NET Core MVC project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using Cookies in ASP.NET Core API Application<\/h2>\n\n\n\n<p>In this section, you will undergo the implementation of cookies in ASP.NET Web API.<\/p>\n\n\n\n<p>For ASP.NET Web API, the cookies are added to the HTTP response using the CookieHeaderValue instance. In addition, System.Net.Http. HttpResponseHeadersExtensions class is also used, as its AddCookies method is required for this implementation. You can add the cookie under the controller by using the below code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public HttpResponseMessage Get()\n{\n    var resp = new HttpResponseMessage();\n\n    var cookie = new CookieHeaderValue(\"session-id\", \"12345\");\n    cookie.Expires = DateTimeOffset.Now.AddDays(1);\n    cookie.Domain = Request.RequestUri.Host;\n    cookie.Path = \"\/\";\n\n    resp.Headers.AddCookies(new CookieHeaderValue&#91;] { cookie });\n    return resp;\n}<\/code><\/pre>\n\n\n\n<p>With the above code, you have received the cookies through a client request. But, if you want to extract them, you should use the GetCookies method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string sessionId = \"\";\n\nCookieHeaderValue cookie = Request.Headers.GetCookies(\"session-id\").FirstOrDefault();\nif (cookie != null)\n{\n    sessionId = cookie&#91;\"session-id\"].Value;\n}<\/code><\/pre>\n\n\n\n<p>Furthermore, if you want structured data to be added to the cookie, the CookieHeaderValue class will be used. The primary purpose of this class is to pass name-value pair list encoded in the URL form data. For implementation, define the class as the following block.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var resp = new HttpResponseMessage();\n\nvar nv = new NameValueCollection();\nnv&#91;\"sid\"] = \"12345\";\nnv&#91;\"token\"] = \"abcdef\";\nnv&#91;\"theme\"] = \"dark blue\";\nvar cookie = new CookieHeaderValue(\"session\", nv); \n\nresp.Headers.AddCookies(new CookieHeaderValue&#91;] { cookie });<\/code><\/pre>\n\n\n\n<p>As a result, you will see an output as the below snippet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Set-Cookie: session=sid=12345&amp;token=abcdef&amp;theme=dark+blue;<\/code><\/pre>\n\n\n\n<p>Additionally, for reading the sub-value transmitted in the cookie request message, use the CookieState class as demonstrated.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string sessionId = \"\";\nstring sessionToken = \"\";\nstring theme = \"\";\n\nCookieHeaderValue cookie = Request.Headers.GetCookies(\"session\").FirstOrDefault();\nif (cookie != null)\n{\n    CookieState cookieState = cookie&#91;\"session\"];\n\n    sessionId = cookieState&#91;\"sid\"];\n    sessionToken = cookieState&#91;\"token\"];\n    theme = cookieState&#91;\"theme\"];\n}<\/code><\/pre>\n\n\n\n<p>Till now, we have learned the implementation of cookies in the API controller. But there&#8217;s also another method in which message handlers are used. This method is way older and preferred than controllers, as it leverages a reading cookie before it gets received or sent by the controller in the request and response.<\/p>\n\n\n\n<p>Now, you will be looking at, for example, where session IDs will be created and added to the cookie in an HTTP request. If there&#8217;s no session ID, the handler will automatically create one and add it to the cookie using HttpRequestMessage.Properties. Similarly, the handler will do for a response, i.e., add session ID in the response cookie.<\/p>\n\n\n\n<p>Code for the handler example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nusing System.Net;\nusing System.Net.Http;\nusing System.Net.Http.Headers;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing System.Web.Http;\n\npublic class SessionIdHandler : DelegatingHandler\n{\n    public static string SessionIdToken = \"session-id\";\n\n    async protected override Task&lt;HttpResponseMessage&gt; SendAsync(\n        HttpRequestMessage request, CancellationToken cancellationToken)\n    {\n        string sessionId;\n\n        \/\/ Try to get the session ID from the request; otherwise create a new ID.\n        var cookie = request.Headers.GetCookies(SessionIdToken).FirstOrDefault();\n        if (cookie == null)\n        {\n            sessionId = Guid.NewGuid().ToString();\n        }\n        else \n        {\n            sessionId = cookie&#91;SessionIdToken].Value;\n            try\n            {\n                Guid guid = Guid.Parse(sessionId);\n            }\n            catch (FormatException)\n            {\n                \/\/ Bad session ID. Create a new one.\n                sessionId = Guid.NewGuid().ToString();\n            }\n        }\n\n        \/\/ Store the session ID in the request property bag.\n        request.Properties&#91;SessionIdToken] = sessionId;\n\n        \/\/ Continue processing the HTTP request.\n        HttpResponseMessage response = await base.SendAsync(request, cancellationToken);\n\n        \/\/ Set the session ID as a cookie in the response message.\n        response.Headers.AddCookies(new CookieHeaderValue&#91;] {\n            new CookieHeaderValue(SessionIdToken, sessionId) \n        });\n\n        return response;\n    }\n}<\/code><\/pre>\n\n\n\n<p>The HttpRequestMessage.Properties bag will provide a session ID to the controller.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public HttpResponseMessage Get()\n{\n    string sessionId = Request.Properties&#91;SessionIdHandler.SessionIdToken] as string;\n\n    return new HttpResponseMessage()\n    {\n        Content = new StringContent(\"Your session ID = \" + sessionId)\n    };\n}<\/code><\/pre>\n\n\n\n<p>That&#8217;s how you can use cookies in the ASP.NET Core Web API application. Now, you understand the cookies implementation in ASP.NET Core Web App and Web API. However, ensure that whenever you use any of the provided code, test and debug it before final implementation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>Cookies are beneficial for an ASP.NET Core web application. It helps improve user experience, analyze daily website visits, provide location-based services, and maintain sessions in a server-client <a href=\"https:\/\/positiwise.com\/blog\/clean-architecture-net-core\">clean architecture<\/a>. Every business needs to use cookies and to do so, you need to understand the fundamental syntax, class, and methods used for it.<\/p>\n\n\n\n<p>You can understand how cookies can be used in the ASP.NET MVC project from the code blocks provided above. In addition, the code provides insight into cookie implementation within a controller and for ASP.NET Core Web API. By following the structure, you can use cookies and take advantage of them effortlessly. However, remember to follow all security measures or to onboard an experienced .NET development team.<\/p>\n  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Related Posts<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"800\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg 1200w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-300x200.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-1024x683.jpg 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-768x512.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n        .Net Core vs. Java \u2013 Which One You Should Use for Your Projects?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"Hire ASP.NET Developers - A Precise Road Map to Employ ASP.NET Developers\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n        Precise Road Map for ASP.NET Developers  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".NET Core vs Node.js: The Difference Explained by Web Expert\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-jpg.webp\" class=\"attachment-full size-full wp-post-image\" alt=\"NET-Core-VS-Node-js\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-jpg.webp 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-300x182.webp 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-768x467.webp 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".NET Core vs Node.js: The Difference Explained by Web Expert\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\">\r\n        .NET Core vs Node.js: The Difference Explained by Web Expert  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 5px;\r\n      padding: 0px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 2rem !important;\r\n      color: #212529 !important;\r\n          }\r\n\r\n    .related-post .headline {\r\nmargin-top: 0;\r\npadding-left: 1%;\r\n}.related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 0px 0px 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 1rem;\r\n      color: #212529;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 13px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 3,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 3,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: true,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: true,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Quick Overview:In this blog, you are going to discover the cookies fundamentals and the correct way to utilize [&hellip;]<\/p>\n  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Related Posts<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n\r\n      <img width=\"1200\" height=\"800\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg 1200w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-300x200.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-1024x683.jpg 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-768x512.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n        .Net Core vs. Java \u2013 Which One You Should Use for Your Projects?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n\r\n      <img width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"Hire ASP.NET Developers - A Precise Road Map to Employ ASP.NET Developers\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n        Precise Road Map for ASP.NET Developers  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"A Descriptive Guide to .NET Framework\" href=\"https:\/\/positiwise.com\/blog\/a-descriptive-guide-to-dot-net-framework\">\r\n\r\n      <img width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"A Descriptive Guide to .NET Framework\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"A Descriptive Guide to .NET Framework\" href=\"https:\/\/positiwise.com\/blog\/a-descriptive-guide-to-dot-net-framework\">\r\n        A Descriptive Guide to .NET Framework  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 5px;\r\n      padding: 0px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 2rem !important;\r\n      color: #212529 !important;\r\n          }\r\n\r\n    .related-post .headline {\r\nmargin-top: 0;\r\npadding-left: 1%;\r\n}.related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 0px 0px 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 1rem;\r\n      color: #212529;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 13px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 3,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 3,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: true,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: true,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>\r\n","protected":false},"author":3,"featured_media":14313,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-14303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v24.6 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use Cookies in ASP.NET Core? - A Complete Guide<\/title>\n<meta name=\"description\" content=\"Learn how to work with cookies in ASP.NET Core - set, get, delete cookies and configure cookie settings like expiration and security.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use Cookies in ASP.NET Core?\" \/>\n<meta property=\"og:description\" content=\"Learn how to work with cookies in ASP.NET Core - set, get, delete cookies and configure cookie settings like expiration and security.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core\" \/>\n<meta property=\"og:site_name\" content=\"Positiwise\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/positiwise\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-30T06:57:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-01T09:16:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/how-to-use-cookies-in-asp-dot-net-core.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1021\" \/>\n\t<meta property=\"og:image:height\" content=\"621\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Parag Mehta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@positiwise\" \/>\n<meta name=\"twitter:site\" content=\"@positiwise\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Parag Mehta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core\"},\"author\":{\"name\":\"Parag Mehta\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/person\\\/b4b3d9970ea94f5914a615f70345353a\"},\"headline\":\"How to Use Cookies in ASP.NET Core?\",\"datePublished\":\"2023-10-30T06:57:06+00:00\",\"dateModified\":\"2023-11-01T09:16:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core\"},\"wordCount\":1789,\"publisher\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/how-to-use-cookies-in-asp-dot-net-core.jpg\",\"articleSection\":[\".NET Development\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core\",\"name\":\"How to Use Cookies in ASP.NET Core? - A Complete Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/how-to-use-cookies-in-asp-dot-net-core.jpg\",\"datePublished\":\"2023-10-30T06:57:06+00:00\",\"dateModified\":\"2023-11-01T09:16:39+00:00\",\"description\":\"Learn how to work with cookies in ASP.NET Core - set, get, delete cookies and configure cookie settings like expiration and security.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#primaryimage\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/how-to-use-cookies-in-asp-dot-net-core.jpg\",\"contentUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/how-to-use-cookies-in-asp-dot-net-core.jpg\",\"width\":1021,\"height\":621,\"caption\":\"How to Use Cookies in ASP.NET Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/how-to-use-cookies-in-asp-net-core#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/positiwise.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use Cookies in ASP.NET Core?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/\",\"name\":\"Positiwise\",\"description\":\"Providing Full-cycle Software Development Services\",\"publisher\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"},\"alternateName\":\"Positiwise Software Pvt Ltd\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\",\"name\":\"Positiwise\",\"alternateName\":\"Positiwise Software Pvt Ltd\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"width\":202,\"height\":29,\"caption\":\"Positiwise\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/positiwise\\\/\",\"https:\\\/\\\/x.com\\\/positiwise\",\"https:\\\/\\\/github.com\\\/positiwise\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/positiwise\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/person\\\/b4b3d9970ea94f5914a615f70345353a\",\"name\":\"Parag Mehta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"caption\":\"Parag Mehta\"},\"description\":\"Parag Mehta, the CEO and Founder of Positiwise Software Pvt Ltd has extensive knowledge of the development niche. He is implementing custom strategies to craft highly-appealing and robust applications for its clients and supporting employees to grow and ace the tasks. He is a consistent learner and always provides the best-in-quality solutions, accelerating productivity.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/paragcmehta\"],\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/author\\\/parag-mehta\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use Cookies in ASP.NET Core? - A Complete Guide","description":"Learn how to work with cookies in ASP.NET Core - set, get, delete cookies and configure cookie settings like expiration and security.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core","og_locale":"en_US","og_type":"article","og_title":"How to Use Cookies in ASP.NET Core?","og_description":"Learn how to work with cookies in ASP.NET Core - set, get, delete cookies and configure cookie settings like expiration and security.","og_url":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core","og_site_name":"Positiwise","article_publisher":"https:\/\/www.facebook.com\/positiwise\/","article_published_time":"2023-10-30T06:57:06+00:00","article_modified_time":"2023-11-01T09:16:39+00:00","og_image":[{"width":1021,"height":621,"url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/how-to-use-cookies-in-asp-dot-net-core.jpg","type":"image\/jpeg"}],"author":"Parag Mehta","twitter_card":"summary_large_image","twitter_creator":"@positiwise","twitter_site":"@positiwise","twitter_misc":{"Written by":"Parag Mehta","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#article","isPartOf":{"@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core"},"author":{"name":"Parag Mehta","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/person\/b4b3d9970ea94f5914a615f70345353a"},"headline":"How to Use Cookies in ASP.NET Core?","datePublished":"2023-10-30T06:57:06+00:00","dateModified":"2023-11-01T09:16:39+00:00","mainEntityOfPage":{"@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core"},"wordCount":1789,"publisher":{"@id":"https:\/\/positiwise.com\/blog\/#organization"},"image":{"@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#primaryimage"},"thumbnailUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/how-to-use-cookies-in-asp-dot-net-core.jpg","articleSection":[".NET Development"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/positiwise.com\/blog\/#organization"}},{"@type":"WebPage","@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core","url":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core","name":"How to Use Cookies in ASP.NET Core? - A Complete Guide","isPartOf":{"@id":"https:\/\/positiwise.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#primaryimage"},"image":{"@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#primaryimage"},"thumbnailUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/how-to-use-cookies-in-asp-dot-net-core.jpg","datePublished":"2023-10-30T06:57:06+00:00","dateModified":"2023-11-01T09:16:39+00:00","description":"Learn how to work with cookies in ASP.NET Core - set, get, delete cookies and configure cookie settings like expiration and security.","breadcrumb":{"@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#primaryimage","url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/how-to-use-cookies-in-asp-dot-net-core.jpg","contentUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/how-to-use-cookies-in-asp-dot-net-core.jpg","width":1021,"height":621,"caption":"How to Use Cookies in ASP.NET Core"},{"@type":"BreadcrumbList","@id":"https:\/\/positiwise.com\/blog\/how-to-use-cookies-in-asp-net-core#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/positiwise.com\/blog"},{"@type":"ListItem","position":2,"name":"How to Use Cookies in ASP.NET Core?"}]},{"@type":"WebSite","@id":"https:\/\/positiwise.com\/blog\/#website","url":"https:\/\/positiwise.com\/blog\/","name":"Positiwise","description":"Providing Full-cycle Software Development Services","publisher":{"@id":"https:\/\/positiwise.com\/blog\/#organization"},"alternateName":"Positiwise Software Pvt Ltd","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/positiwise.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/positiwise.com\/blog\/#organization","name":"Positiwise","alternateName":"Positiwise Software Pvt Ltd","url":"https:\/\/positiwise.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/07\/logo.png","contentUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/07\/logo.png","width":202,"height":29,"caption":"Positiwise"},"image":{"@id":"https:\/\/positiwise.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/positiwise\/","https:\/\/x.com\/positiwise","https:\/\/github.com\/positiwise","https:\/\/www.linkedin.com\/company\/positiwise"]},{"@type":"Person","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/person\/b4b3d9970ea94f5914a615f70345353a","name":"Parag Mehta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","caption":"Parag Mehta"},"description":"Parag Mehta, the CEO and Founder of Positiwise Software Pvt Ltd has extensive knowledge of the development niche. He is implementing custom strategies to craft highly-appealing and robust applications for its clients and supporting employees to grow and ace the tasks. He is a consistent learner and always provides the best-in-quality solutions, accelerating productivity.","sameAs":["https:\/\/www.linkedin.com\/in\/paragcmehta"],"url":"https:\/\/positiwise.com\/blog\/author\/parag-mehta"}]}},"_links":{"self":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/14303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/comments?post=14303"}],"version-history":[{"count":9,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/14303\/revisions"}],"predecessor-version":[{"id":14377,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/14303\/revisions\/14377"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/media\/14313"}],"wp:attachment":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/media?parent=14303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/categories?post=14303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/tags?post=14303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}