public ActionResult Index() { //Session Session["check"] = "test"; System.Web.HttpContext.Current.Session["check2"] = "test2"; var data = (string)System.Web.HttpContext.Current.Session["check2"]; HttpSessionStateBase datas = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session); datas.Add("check3", "test3"); //Hiddenfield var model = new DemoModel { Property1 = 10, Property2 = 20 }; //Cookies //ViewData ViewData.Add(new KeyValuePair <string, object>("", "10")); //ViewBag //TempData //TempData.Add("Count",10); return(View(model)); }
/// <summary> /// Hàm thiết lập tham số vào session /// </summary> /// <param name="page">URL trang cần chuyển đến</param> /// <param name="request">Tham số cần lưu trữ vào Session</param> public static void cauHinhSession(string page, string request) { HttpSessionStateBase Session = new HttpSessionStateWrapper(HttpContext.Current.Session); string param = "page=" + page + "|request=" + request; //------Thiết lập lại session Session.Remove("urlAction"); Session.Add("urlAction", ""); Session["urlAction"] = param; }
//public static HttpSessionState session { get; set; } public static void set(string key, object value) { HttpSessionStateBase session = new HttpSessionStateWrapper(System.Web.HttpContext.Current.Session); try { if (session != null) { if (session[key] != null) { session[key] = value; } else { session.Add(key, value); } } }catch (Exception ex) { } }