I need to be able to register a route via an instance of RouteCollection to an area. I couldn’t put it in the normal area route registration as it had to be registered last. It took a while to figure out that this works:
public static void RegisterAreaRoute(RouteCollection routes) {
routes.MapRoute(
"MyRouteName",
"{*path}",
new
{
// options
},
new[] { "_Namespace_.Areas._Area_Name_.Controllers" }
).DataTokens.Add("area", _Area_Name_);
}
Archive for the ‘Web Development’ Category
ASP.NET MVC Route Registration and Areas
ASP.NET MVC for PHP Programmers
Routes are rewrite rules with the “object defaults” part of the routes being similar to the variables parsed out of the URL via mod_rewrite (but they the “object defaults” can store values from other sources so the routes are somewhat like a data store).
ViewData[] is similar to a global variable in PHP and it is populated by the Controllers and seen by the Models.
Lots of differences of course but just a quick thought…
Attractive URLs on Database-driven Websites
One of the annoyances with moving from URLs based on actual files on a file system to database-driven websites is ugly URLs. There are a lot of articles on working around the problem. Typically, the solution is having a numeric identifier along with a more verbose string that identifies the article. The verbose string is then ignored by the application.
This approach makes a lot of sense when listing categories of things that include many items. Common examples would be movies, books, etc. If a numeric identifier was not used then the database lookup would need to be based on the verbose string. There are two issues here: database lookups based on strings are inefficient compared to numeric values and the longer the URL the more likely it will be accidentally corrupted when used outside of the application (say in an email).
However, I argue that always using the numeric identifier is not necessary. A first class URL (one without a numeric identifier) should be used when possible. Two methods of doing this come to mind: registering all the URLs that are first class with the application so that the URL to numeric identifier is known by the application without a database lookup or by doing a database lookup based on the verbose string. I believe the first method is most performant so that is the route I am going to investigate first. I also believe the second method can be made to perform well particularly when there are a limited number of first class URLs (I am not arguing that one should use first class URLs for categories with large numbers of entries) however there are issues besides performance (see the case where the URL includes a “/” within the entry name but “/” is also used to separate the entries — I suspect this is easier to handle with the first method).
My next article will focus on an implementation of this in ASP.NET MVC although this post has nothing to do with any particular platform so the same methods should work with any platform. One critical requirement is that URLs can be registered/deregistered during runtime in the event of adding/removing content.
ASP.NET MVC Overview in VWD 2010 Beta 2: Create a Movie Database Application in 15 Minutes with ASP.NET MVC (C#)
I am going to blog about each tutorial mentioning just the issues encountered with VWD 2010 Beta 2 and ASP.NET MVC 2 RC installed.
- The Model generated using the Microsoft Entity Framework named “MoviesDBModel.edmx” did not have MovieSet as in the article but instead Movies1. There is an option in MoviesDBModel.edmx on the properties of Movie that has “Entity Set Name” defaulting to Movies1 — that should be changed to MovieSet.
Getting started with ASP.NET MVC 2 RC 2 on Visual Web Developer (VWD) 2010 Express Beta 2
Download the ISO instead of doing the installs over the net as it is highly likely that more than one installation attempt will be needed to get everything installed.
- Install Visual Web Developer 2010 Express Beta 2 from ISO (if virtually mounting the disk, make the mount persistent as there is a reboot halfway through the install and if the disk is not present, the install bails).
- Uninstall “Microsoft ASP.NET MVC 2″ but not “Microsoft ASP.NET MVC 2 – VWD Express 2010 Tools”. The VWD 2010 Express Beta 2 comes with a version of ASP.NET MVC that is pre-RC.
- Install AspNetMVC2_RC2_VS2008.exe (yes, that is the correct version for ASP.NET MVC 2 RC even though it has 2008 in the name).
- If “Microsoft Visual Studio 2010 ADO.NET Entity Framework Tools Beta 2″ does not show up in Add/Remove Programs then force it to install by opening a command prompt and going to the \VWDExpress\wcu\EFTools directory of the CD and running ADONETEntityFrameworkTools_enu.msi USING_EXUIH=1 /log “dd_ADONETEntityFrameworkTools_enu_MSI.txt”