简体   繁体   中英

Hundreds of ASP.NET MVC Routes

So I have an application I am working on at work that we have a few hundred clients running on. We are working on a brand spanking new ASP.NET MVC 3 app for it, and I am working on the routes for this app.

I posted recently on a solution I came up with for dynamic routes, and it works fine on a few entries I have in a Sql Express DB. Essentiall it creates routes for every entry that I have in this DB.

So, my question is...If I were to implement this on an enterprise application, would the creation of several hundred if not thousands of routes added into my application have any negative consequences?

Concerning the dynamic route table, there is a recommendation which you seem to follow already :

Use named routes. Named routes are an optional feature of routing. The names only apply to URL generation - they are never used for matching incoming URLs. When you specify a name when generating a URL we will only try to match that one route. This means that even if the named route you specified is the 100th route in the route table we'll jump straight to it and try to match.

Besides the number of customers / routes, you should also consider the estimated number of requests per day (for which you should be worried more, IMHO), and take into account the scalability of your web server (worker threads, hardware, ...) in consequence.

If you clients use own domains with you application, use custom IRouteConstraint in routes to check request domain and filter only this routes. Tt's solution also protect routing from collisions.

So best way for you to both task - routing request and building links - use cached routing.

  1. You can inherits and extend default MVC Route class
  2. To speedup link building: Override GetVirtualPath that calculate hash from RouteData values and using it to put and get url values to and from cache.
  3. To speedup routing: override GetRouteData also to use cashed RouteDate with url hash.

This solution may be requred more memory, but in most cases you have limited set of url on pages.

You question is slightly unclear. By "dynamic route" do you mean you go to the DB tier on a request to resolve the route or do you query against your db to create the source file for the route table?

In the first case performance should be constant. (The overhead of checking the DB against the number of users you have will not change.) So you should see performance effects right away.

In the second case I expect the routing code will be slower if it has that many items to check -- but it is easy to test.

There is defiantly a performance hit once you start to get over a certain threshold of routes. I don't have any hard benchmarks on this but I have redesigned a few poorly performing sites now.

The more you can use the same route for many different url's with parameters the better.

Just from observation it seems when you start to get close to 1k routes is when it starts really bottoming out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM