Example #1
0
        public ActionResult Index()
        {
            var model = new SetSessionModel {
                Key = "CurrentTime", Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            return(View(model));
        }
Example #2
0
        public ActionResult Index(SetSessionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Session[model.Key] = model.Value;

            ViewBag.Message = "Set Success";

            return(View(model));
        }
        public IActionResult SetSession(SetSessionModel model)
        {
            if (!this.SessionSetEnabled)
            {
                return(NotFound());
            }

            foreach (var item in model.Values)
            {
                this.HttpContext.Session.SetString(item.Name, item.Value);
                this.TempData[item.Name] = item.Value;
            }
            return(Redirect(model.RedirectUrl));
        }
        public IActionResult SetSession(int id)
        {
            if (!this.SessionSetEnabled)
            {
                return(NotFound());
            }

            var model = new SetSessionModel
            {
                Values = Enumerable.Range(0, id).Select(x => new SessionValueModel()).ToList()
            };

            return(View(model));
        }