1.在ConfigureServices中添加

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie();

2.在Configure中添加

 app.UseCookiePolicy();

3.代码中获取cookie

 var cookie = HttpContext.Request.Cookies.FirstOrDefault(m => m.Key =="cookiename");
         
            if (cookie.Key != null)
            {
                string value = cookie.Value;
             
            }

 

4.代码中保存cookie

   Response.Cookies.Append("cookiename", "cookievalue", new CookieOptions
            {

                Expires = DateTime.Now.AddHours(5),

            });

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2022-02-24
  • 2022-12-23
相关资源
相似解决方案