我想从会话中获取密钥,但是编译器抱怨类不是静态的。有人可以帮我吗?
using Microsoft.AspNetCore.Mvc;
using LitOnline_V1.Models;
using Microsoft.AspNetCore.Http;
namespace Test{
public class GetValidateUer{
public int GetUserValidation(){
var isValidated = HttpContext.Session.GetInt32("isValidated");
return isValidated;
}
}
}
严重性代码说明项目文件行抑制状态
Error CS0120 An object reference is required for the non-static field, method, or property 'HttpContext.Session'
答案 0 :(得分:0)
希望有帮助
public class HomeController : Controller
{
public IActionResult Index()
{
MyMethod(HttpContext);
// Some Code
}
}
public void MyMethod(Microsoft.AspNetCore.Http.HttpContext context)
{
var host = $"{context.Request.Scheme}://{context.Request.Host}";
// Some Code
}