How to correctly set cookies (HttpCookie) for ASP.NET Core
Asked Answered
G

1

6

Below are a few different ways I'm trying to set cookies for a user. I don't understand why I'm getting an error on the HttpCookie. If someone knows what I'm doing wrong please let me know or if you need more details on my problem.

enter image description here

enter image description here

Giglio answered 29/4, 2021 at 0:58 Comment(4)
Hi @AverageGuyIssac, does your project using asp.net-mvc or asp.net-core-mvc? Both frameworks are different.Drifter
@YongShun I am using asp.net-core-mvcGiglio
Hi @AveargeGuyIssac, your question is same as HttpCookie class in aspnet core 2. You can read this post & also its linked duplicate questions as well. Thanks.Drifter
Might you please edit your question to include your code and other textual content as text rather than as a screen shot? It's preferred not to use images for this purpose here, see Why not upload images of code/errors when asking a question? and Discourage screenshots of code and/or errors for why.Filibertofilibuster
F
5

Download Package Microsoft.AspNetCore.Http using Nuget Package Manager, refer this package in your class by writing using Microsoft.AspNetCore.Http;

Instead of HTTPCookie class ,You need to use CookieOptions Class as follow

CookieOptions langCookie=new CookieOptions(); langCookie.Expires=DateTime.Now.AddYears(1);

Fescennine answered 13/10, 2022 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.