Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC - Creating a custom Uri to Route mapping handler
    text
    copied!<p>I'm looking to heavily customize the way my application handles Routes. Essentially, I want to achieve a process something like this:</p> <ul> <li>User requests URL: /custom-url-part-1/custom-url-part-2/gallery/1/date</li> <li>Application looks for a match in a database table of Routes</li> <li>Application returns matching Route record, consisting of: <ul> <li>RouteUrl</li> <li>Controller</li> <li>Action</li> <li>Parameters</li> <li>Defaults</li> </ul></li> <li>Application looks at RouteUrl and parses any optional parameters {pagenum}, {orderby}</li> <li>Application checks if these have been supplied in the requested Url</li> <li>If they have not been supplied, it checks the "Defaults" of the Route record to get them <ul> <li>These are then passed in the RouteData defaults</li> </ul></li> <li>Parameters are passed in the RouteData defaults</li> <li>Route data is returned</li> </ul> <p>The core reason for this is I want to have a dynamic table of Routes, that is modified by a CMS in order to store certain data against routes.</p> <p>The questions I have are:</p> <p>How can I replicate the way that MVC matches a Uri to a Route? I need to essentially look through the database table and bring back the appropriate Route based on the Uri. Very similar to how the standard ASP.NET MVC functionality looks through the RouteCollections and uses the correct route.</p> <p>I realise I'm essentially rewriting some functionality that MVC supplies built-in, and replacing the RoutesCollection with a database... but I need to do that in order to achieve two things:</p> <ol> <li>The routes being entirely dynamic, fluid and controlled by the CMS.</li> <li>Data being stored against those routes which can't be inferred from the Uri itself (so for example, I might want to send a PageId through when a user hits a particular route, but I don't want that PageId in the Uri).</li> </ol>
 

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