我正在尝试在HttpContext.Current.Session["TestModel"]
方法中将模型数据保存在POST
中,并试图在HttpContext.Current.Session["TestModel"]
方法中从GET
中检索相同的模型数据。以下是我正在尝试的代码:
[HttpPost]
public async Task<HttpResponseMessage> UploadDataJson(HttpRequestMessage request)
{
var session = HttpContext.Current.Session;
OasisSessionModel oasissessionmodel = new OasisSessionModel(); //I tried setting it as a global
oasissessionmodel.TotalRows = 200;
HttpContext.Current.Session["TestModel"] = oasissessionmodel;
return someresponse;
}
[HttpGet]
[Route("api/GetUploadUpdates")]
public IHttpActionResult GetUploadUpdates()
{
var session = HttpContext.Current.Session;
OasisSessionModel oasissessionmodel = null;
oasissessionmodel = HttpContext.Current.Session["TestModel"] as OasisSessionModel;
return Ok();
}
但是在这种情况下,HttpContext.Current.Session["TestModel"]
始终为null
,是否还有其他方法可以在WEB API中全局处理会话。预先感谢