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
  • 173,679
  • 45
  • 326
  • 490
Bias Tegaralaga
  • 2,100
  • 5
  • 20
  • 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,253
  • 16
  • 29
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
  • 73,615
  • 63
  • 359
  • 429