Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is fairly old now, nut just in case anyone else is looking for something similar...</p> <p>Unless I'm completely misunderstanding what you want to do, it's pretty simple really.</p> <p>Step 1: Add a new route to global.ascx.cs containing a reference to your personal routing engine</p> <pre><code>routes.Add(new MyProject.Routing.ContentRoutingEngine()); </code></pre> <p>Make sure that it is in the right place in the list of routes so that other routing engines can catch stuff before it if required, or continue the route search if your engine doesn't handle a particular route. I put it after the ignores, but before the MVC default routes.</p> <p>Step 2: Create the Content Routing Engine, making sure that it inherites from System.Web.Routing.RouteBase abstract class, and overrides the GetRouteData and GetVirtualPath methods as required e.g.</p> <pre><code>public class ContentRoutingEngine : RouteBase { public override RouteData GetRouteData(HttpContextBase httpContext) { var routeHandler = new MvcRouteHandler(); var currentRoute = new Route("{controller}/{action}", routeHandler); var routeData = new RouteData(currentRoute, routeHandler); // set your values dynamically here routeData.Values["controller"] = "Home" ; // or routeData.Values.Add("action", "Index"); // return the route, or null to have it passed to the next routing engine in the list return routeData; } public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) { //implement this to return url's for routes, or null to just pass it on return null; } } </code></pre> <p>and that should do it. You can change routes as dynamically as you wish within your engine, and no changes to MVC source required. Let the standard MVC RouteHandler actually invoke the controller.</p> <p>Postscript: Obviously the code above is not production standard - it's written to make it as obvious as possible what's going on.</p>
    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