Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about a TransferResult class? (based on <a href="https://stackoverflow.com/questions/799511/how-to-simulate-server-transfer-in-asp-net-mvc/892545#892545">Stans answer</a>)</p> <pre><code>/// &lt;summary&gt; /// Transfers execution to the supplied url. /// &lt;/summary&gt; public class TransferResult : ActionResult { public string Url { get; private set; } public TransferResult(string url) { this.Url = url; } public override void ExecuteResult(ControllerContext context) { if (context == null) throw new ArgumentNullException("context"); var httpContext = HttpContext.Current; // MVC 3 running on IIS 7+ if (HttpRuntime.UsingIntegratedPipeline) { httpContext.Server.TransferRequest(this.Url, true); } else { // Pre MVC 3 httpContext.RewritePath(this.Url, false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(httpContext); } } } </code></pre> <p><strong>Updated:</strong> Now works with MVC3 (using code from <a href="https://stackoverflow.com/questions/799511/how-to-simulate-server-transfer-in-asp-net-mvc/1242525#1242525">Simon's post</a>). It <em>should</em> (haven't been able to test it) also work in MVC2 by looking at whether or not it's running within the integrated pipeline of IIS7+.</p> <p>For full transparency; In our production environment we've never use the TransferResult directly. We use a TransferToRouteResult which in turn calls executes the TransferResult. Here's what's actually running on my production servers.</p> <pre><code>public class TransferToRouteResult : ActionResult { public string RouteName { get;set; } public RouteValueDictionary RouteValues { get; set; } public TransferToRouteResult(RouteValueDictionary routeValues) : this(null, routeValues) { } public TransferToRouteResult(string routeName, RouteValueDictionary routeValues) { this.RouteName = routeName ?? string.Empty; this.RouteValues = routeValues ?? new RouteValueDictionary(); } public override void ExecuteResult(ControllerContext context) { if (context == null) throw new ArgumentNullException("context"); var urlHelper = new UrlHelper(context.RequestContext); var url = urlHelper.RouteUrl(this.RouteName, this.RouteValues); var actualResult = new TransferResult(url); actualResult.ExecuteResult(context); } } </code></pre> <p>And if you're using <a href="http://mvccontrib.codeplex.com/wikipage?title=T4MVC" rel="noreferrer">T4MVC</a> (if not... do!) this extension might come in handy.</p> <pre><code>public static class ControllerExtensions { public static TransferToRouteResult TransferToAction(this Controller controller, ActionResult result) { return new TransferToRouteResult(result.GetRouteValueDictionary()); } } </code></pre> <p>Using this little gem you can do</p> <pre><code>// in an action method TransferToAction(MVC.Error.Index()); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload