Does anyone know how to redirect current request in ASP.NET using http status code 303 (SeeOther).
Code snippets are more than welcome!
You should be able to do it like this:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Status = "303 See Other";
HttpContext.Current.Response.AddHeader("Location", newLocation);
HttpContext.Current.Response.End();
This is a .NetCore / .Net5.0+ implementation as an extension method.
public static class ControllerExtensions
{
public static ActionResult SeeOther(this Controller controller, string location)
{
controller.Response.Headers.Add("Location", location);
return new StatusCodeResult(303);
}
}
Usage From Controller: return this.SeeOther("/resource-endpoint");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With