Session,token和cookie简介,待续

1.Session

startup.cs

public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();

services.AddSession();
}

app.UseSession();

     

public IActionResult Index() { var user = base.HttpContext.Session.GetString("CurrentUser"); if (string.IsNullOrEmpty(user)) { base.HttpContext.Session.SetString("CurrentUser", DateTime.Now.ToString()); } base.ViewBag.User = base.HttpContext.Session.GetString("CurrentUser"); return View(); }

刷新后,时间是固定的

 

posted @ 2021-10-31 22:47  留下成长的足迹  阅读(24)  评论(0编辑  收藏  举报