code_junkie

Asp.Net MVC - Best approach for “dynamic” routing

Nov 13th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. private static string GetRouteURL(object routeValues)
  2. {
  3. UrlHelper url = new UrlHelper(
  4. new RequestContext(
  5. new HttpContextWrapper(HttpContext.Current),
  6. new RouteData()),
  7. RouteTable.Routes);
  8. return url.RouteUrl(routeValues);
  9. }
  10.  
  11. public override void ExecuteResult(ControllerContext context)
  12. {
  13. var httpContext = HttpContext.Current;
  14.  
  15. // ASP.NET MVC 3.0
  16. if (context.Controller.TempData != null &&
  17. context.Controller.TempData.Count() > 0)
  18. {
  19. throw new ApplicationException(
  20. "TempData won't work with Server.TransferRequest!");
  21. }
  22. // change to false to pass query string parameters
  23. // if you have already processed them
  24. httpContext.Server.TransferRequest(Url, true);
  25.  
  26. // ASP.NET MVC 2.0
  27. //httpContext.RewritePath(Url, false);
  28. //IHttpHandler httpHandler = new MvcHttpHandler();
  29. //httpHandler.ProcessRequest(HttpContext.Current);
  30. }
  31. }
Add Comment
Please, Sign In to add comment