How to create a Cookie in C#, which is both side modifiable.
How to create a Cookie in C#, which is both side modifiable.
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Utpal Vishwas
21-May-2025In C#, you can create a cookie that is modifiable from both the client-side (JavaScript) and server-side (C#) by ensuring the cookie meets these two criteria:
Key Requirements
HttpOnly = false— so JavaScript can read/modify it.Secureflag (unless using HTTPS).Path = "/"if you want it globally accessible.1. Set a Modifiable Cookie in C# (Server-Side)
In ASP.NET MVC or WebForms, you can use:
In ASP.NET Core:
2. Access and Modify the Cookie via JavaScript (Client-Side)
3. Modify the Cookie in C# Again (Optional)
Important Notes