我需要将MVC项目迁移到.net Core,我知道它已经从ASP.net Core中删除了System.Web。我需要转换HttpContext.Current.Session [“ name”]! =在asp.net核心为零。我补充说:使用Microsoft.AspNetCore.Http但我有一个错误。
您是否测试过Microsoft doc,示例如下:>
public const string SessionKeyName = "_Name";
public const string SessionKeyAge = "_Age";
const string SessionKeyTime = "_Time";
// Requires: using Microsoft.AspNetCore.Http;
if (string.IsNullOrEmpty(HttpContext.Session.GetString(SessionKeyName)))
{
HttpContext.Session.SetString(SessionKeyName, "The Doctor");
HttpContext.Session.SetInt32(SessionKeyAge, 773);
}
var name = HttpContext.Session.GetString(SessionKeyName);
var age = HttpContext.Session.GetInt32(SessionKeyAge);