3

How to redirect page in ASP MVC 4?

I've tried Redirect, RedirectPermanent, RedirectToAction, and so on. But it is like HTTP Redirect (using http-equiv refresh), not Header Redirect. It will display Header Status 302 first, then redirect. I want header redirect like in php header('location:/');

 

[HttpGet]
public ActionResult SignOut()
{
    UtilsHelper.NoCache();
    session.Destroy();
    return RedirectToAction("Index", "Home");
}
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Bias Tegaralaga
  • 2,240
  • 5
  • 21
  • 26

2 Answers2

3

If you are really worried about the redirect code you could control it at a lower level.

[HttpGet]
public ActionResult SignOut()
{
    UtilsHelper.NoCache();
    session.Destroy();
    HttpContext.Response.Clear();
        HttpContext.Response.StatusCode = 302; //change it to 301?
        HttpContext.Response.RedirectLocation = "/";
        HttpContext.Response.End();
}

Im not sure what is the issue with 302 here?

Gavin
  • 1,233
  • 17
  • 30
0

You can use Server.Transfer instead of Response.Redirect

See
How to simulate Server.Transfer in ASP.NET MVC?
for further information

Community
  • 1
  • 1
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442