• asp.net core 3.1 中使用cookie


    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),
    
                });
  • 相关阅读:
    C
    大数模板
    51Nod 1040 最大公约数之和
    欧拉函数
    51Nod 1384 全排列
    B
    A
    B. Mancala (Codeforces Round #478 (Div. 2))
    I
    Requests 入门
  • 原文地址:https://www.cnblogs.com/lkd3063601/p/13913424.html
Copyright © 2020-2023  润新知