TransferResult implementation in MVC 3 RC - not working

Any ideas for troubleshooting below?

There is an excellent TransferResult implementation here that works great on MVC 1.2 but doesn't work on MVC 3 RC.

public class TransferResult : RedirectResult { public TransferResult(string url): base(url) { } public override void ExecuteResult(ControllerContext context) { var httpContext = HttpContext.Current; httpContext.RewritePath(Url, false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); } } 

In MVC 3 RC, HTTPHandler.ProcessRequest fails and says 'HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised.

How to rewrite this code to do this?

UPD . The code works if it is running on the VS 2010 embedded development server, but does not work on the local IIS 7.5 host. The problem is still not resolved.

UPD2 This answer contains a modified TransferResult implementation that works with MVC3. It turns out it's even easier than before.

+5
source share
2 answers

Unable to play. In MVC 3 RC (Razor and WebForms) works fine:

 public class TransferResult : RedirectResult { public TransferResult(string url) : base(url) { } public override void ExecuteResult(ControllerContext context) { var httpContext = HttpContext.Current; httpContext.RewritePath(Url, false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); } } public class HomeController : Controller { public ActionResult Index() { return new TransferResult("/Home/About"); } public ActionResult About() { return View(); } } 
+1
source

Personally, I believe that creating routes (with route restrictions if necessary (see http://stephenwalther.com/blog/archive/2008/08/07/asp-net-mvc-tip-30-create-custom-route- constraints.aspx ) is much preferable to this “hack”, which attempts to perform an invisible redirection, so the request is processed by a different controller and action than the one specified by routing.

Why can't you just use routing?

0
source

All Articles