Does anybody know how to redirect to another server/solution using ASP.NET MVC? Something like this:
public void Redir(String param)
{
// Redirect to anot
The RedirectResult
will give you a 302, however if you need a 301 use this result type:
public class PermanentRedirectResult : ActionResult
{
public string Url { get; set; }
public PermanentRedirectResult(string url)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException("url is null or empty", "url");
}
this.Url = url;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.HttpContext.Response.StatusCode = 301;
context.HttpContext.Response.RedirectLocation = Url;
context.HttpContext.Response.End();
}
}
Then use it like mentioned above:
public PermanentRedirectResult Redirect()
{
return new RedirectResult("http://www.google.com");
}
Source (as it's not my work): http://forums.asp.net/p/1337938/2700733.aspx
public ActionResult Redirect()
{
return new RedirectResult("http://www.google.com");
}
hope this helps :-)
// It was not working in my case so I did some trick here.
public ActionResult Redirect()
{
return new PermanentRedirectResult ("http://www.google.com");
}