Return 307 Temporary Redirect in ASP.NET MVC

后端 未结 3 1552
深忆病人
深忆病人 2020-12-19 01:49

Is it possible to return a 307 Temporary Redirect from a controller in ASP.NET MVC?

I sometimes need to re-POST the values submitt

相关标签:
3条回答
  • 2020-12-19 01:56

    To return a 307 redirect result from an MVC action, use the following:

    public ActionResult Action()
    {
        string url = GetRedirectUrl()
        HttpContext.Response.AddHeader("Location", url);
        return new HttpStatusCodeResult(307);
    }
    
    0 讨论(0)
  • 2020-12-19 02:02

    Take a look at the following article - you can use the same technique for 307:

    301 Redirects

    0 讨论(0)
  • 2020-12-19 02:08

    ASP.NET Core:

     public RedirectResult (string url, bool permanent, bool preserveMethod);
    

    So

    return Redirect(url, false, false); // 302
    return Redirect(url, true, false);  // 301
    return Redirect(url, false, true);  // 307
    return Redirect(url, true, true);   // 308
    
    0 讨论(0)
提交回复
热议问题