MSDN中HttpApplicationState 类介绍,Application是HttpApplicationState的实例化
https://msdn.microsoft.com/zh-cn/library/system.web.httpapplicationstate%28v=vs.110%29.aspx
一直不知道怎么调取,询问了一下,Controller中直接通过HTTPContext调取的
HttpContext.Application
使用Application对象
1 public ActionResult TestShow() 2 { 3 return Json(HttpContext.Application["Test"],JsonRequestBehavior.AllowGet); 4 } 5 6 public ActionResult TestWrite() 7 { 8 //加锁,针对并发问题 9 HttpContext.Application.Lock(); 10 var obj = HttpContext.Application["Test"] as List<int>; 11 if (obj == null) 12 { 13 obj = new List<int>() { 1 }; 14 } 15 else 16 { 17 obj.Add(obj.Count + 1); 18 } 19 HttpContext.Application["Test"] = obj; 20 HttpContext.Application.UnLock(); 21 return Json(HttpContext.Application["Test"],JsonRequestBehavior.AllowGet); 22 }