How to simulate Server.Transfer in ASP.NET MVC? -


You can return a Redirect ActionResult very easily to ASP.NET MVC:

 < Code> return redirect action ("index"); Or redirect the route (new {controller = "home", version = Math> random () * 10});  

This will actually give an HTTP redirect, which is usually OK. However, when using Google Analytics it is the cause of big issues because Google is not able to know where you came from when the original modifier is lost. It loses useful information such as the conditions of any search engine.

As a side note, this method has the benefit of removing any parameter that came from the campaign but still allows me to capture them on the server side except by putting them in the query string People go to bookmark or make Twitter or post a link they should not have I have seen this many times, where people get the campaign ID yuk for our site Add links.

Anyway, I'm writing a 'gateway' controller for all incoming visits to the site, which I can redirect to different locations or alternate versions

for now I take more care about Google (from casual bookmarks) for now, and I want to be able to send someone who visits / on the page, if they get Will go to / home / 7 , which is a homep H version 7.

As I said earlier, if I do this, then Google's ability to analyze referrer is reduced:

Return Redirect Tiections (New { Controller = "home", version = 7});

What I really want

  return server transfer action (new {controller = "home", version = 7});  

Which I see without a client side redirection. I do not think such a thing exists.

Currently, the best thing I can do is to duplicate the whole controller argument for HomeController.Index (..) my gateway controller. Index operation means that I had to move 'View / Home' to 'Share' , so it was accessible. Should be a better way ??

How about a transfer square class? (Based)

  /// & lt; Summary & gt; /// Execution transfers to supply URLs. /// & lt; / Summary & gt; Public class transfer results: Proceedings {public string URL {received; Private set; } Public Transit Result (string URL) {this.Url = url; } Public override zero ExecuteResult (Controller Reference Reference) {if (context == null) Remove new logic ("Reference"); Var httpContext = HttpContext.Current; // MVC 3 is running on IIS 7+ (HTTTEMummingIntegratedPipline) {httpContext.Server.TransferRequest (this.Url, true); } And {// pre MVC 3 httpContext.RewritePath (this.Url, false); IHttpHandler httpHandler = New MvcHttpHandler (); HttpHandler.ProcessRequest (HttpContext); }}}  

Renew: now works with MVC3 (using code). Whether it is should (it is not able to test) is also working in MVC2 or not or is not running within the integrated pipeline of IIS7 +.

For complete transparency; In our production environment, we have never used the transfer result, we use a transfteroutout resell, which in turn executes the call transfer result. Here's what's actually going on on my production server.

  Public class transfersOurUR results: Actionsalstalt {public string root name {get; Set; } Receive public routine route values ​​{ Set; } Public Transfer Trurour Route (Root Value Solution Route): This (empty, root value) {} public transfterrorrot result (string root name, root value root value) {this.RouteName = routeName ?? String.Empty; this. Value of route = route value ?? New root valuation (); } Public override zero ExecuteResult (Controller Reference Reference) {if (context == null) Remove new logic ("Reference"); Var urlHelper = new UrlHelper (context.RequestContext); Var url = urlHelper.RouteUrl (this.RouteName, this rootwaves); Var actualResult = new transfer result (url); ActualResult.ExecuteResult (reference); }}  

And if you are using (if not ... do!) This extension might be useful.

  public static class controller extension {public static transferroretrastal transfer transferAction (this controller controller, anxicrous result) {new transistorRoot result (result. GETRouteValueDictionary ()); }}  

You can use this small gem

  // In an action method, TransferToAction (MVC.Error.Index ());  

Comments