如何在MVC3 / Razor中正确重定向(同时设置cookie)?
首先,我感觉Response.Redirect只是经典ASP的遗留物,我应该在MVC范例中使用其他东西。
第二,虽然我当前的Response.Redirect IS实现工作,但它没有设置我想要的cookie。 我假设这是因为标头被删除而不是重定向发送到客户端。
这是我到目前为止:
[HttpPost] public ActionResult Login(FormCollection form) { User user; string sessionKey; if (UserManager.Login(form["Email"], form["Password"])) { // Login stuff here // Remember user's email Response.Cookies["Email"].Value = form["Email"]; Response.Cookies["Email"].Expires = DateTime.Now.AddDays(31); // Redirect to homepage Response.Redirect("~/"); } }
在MVC中return RedirectToAction("Home", "Index")
的正确方法是return RedirectToAction("Home", "Index")
。
Cookie应该有效。
上述就是C#学习教程:如何在MVC3 / Razor中正确重定向(同时设置cookie)?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/942379.html