5

First off, I get the feeling that Response.Redirect is just a leftover from classic ASP, and I should be using something else in the MVC paradigm.

And second, while my current implementation of Response.Redirect IS working, it doesn't set the cookie I want it to. I'm assuming this is because the header gets wiped out instead of sent to the client on redirect.

Here is what I have so far:

    [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("~/");
        }
     }
tereško
  • 58,060
  • 25
  • 98
  • 150
Neil N
  • 24,862
  • 16
  • 85
  • 145

1 Answers1

8

The proper way to redirect in MVC is return RedirectToAction("Home", "Index").

The cookies should work.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Does it actually change the url in the browser as well? Or will the user still see Home/Login ? – Neil N Jun 16 '11 at 13:58
  • It's a real redirect. It calls `Response.Redirect` under the covers after resolving the URL. – SLaks Jun 16 '11 at 14:03