Introducing WebMatrix - An Easier Way To Do ASP.NET

There has been a spate of announcements recently from Scott Guthrie, the main Microsoft man responsible for ASP.NET over the last week or so - the launch of IIS Express, a new version of SQL Server Compact Edition (CE) that can be run in medium trust environments, and a new View Engine and syntax called Razor. Each of these announcements have generated a lot of reaction, and they are each significant in themselves. They all make ASP.NET easier for existing developers. However, if you put them all together, and throw in a new framework and IDE, they make ASP.NET much, much easier for new developers coming to ASP.NET for the first time. So that's what Microsoft have gone and done. And today, they have announced the first Beta version of WebMatrix - a head-on competitor to WAMP stacks.

WebMatrix is a collection of tools which includes IIS Express, an IDE, Sql Server Compact Edition, Razor, and a new programming Framework - Web Pages. It's totally free, and is designed to provide easier entry into ASP.NET development - especially for those used to scripting technologies like PHP and classic ASP or those completely new to dynamic web development.

If you think you have already heard of WebMatrix, you are probably right: the forerunner to Visual Web Developer Express 2005 was called Web Matrix and provided an entry level free IDE for developing ASP.NET 1.1. However, the only thing that the new WebMatrix shares with its predecessor is the name. Gone is Cassini - the lightweight development server that came bundled with the old Web Matrix, and which is still available as the development server within Visual Studio. In its place is the cut down version of the next generation IIS. Alongside that is Web Pages - a totally new framework, which builds on top of ASP.NET. The Web Pages framework includes the new Razor View engine and programming syntax as well as many new helper functions.

The default database for WebMatrix sites will be the new SQL Server Compact Edition (CE) 4.0, and the really great thing about this is that you do not need to negotiate with your web host to deploy it so long as they have .NET 4.0 installed. When you build your site within WebMatrix, the database engine is deployed within the bin directory, with the sdf data file residing in the App_Data folder. The new version has been evolved to support medium trust and can be deployed easily in a shared hosting environment. CE has a number of limitations compared to its grown up cousins, but those limitations are not likely to prevent WebMatrix causing the death of Access as the most popular viable free, easy to install web database. WebMatrix also includes tools so that upgrading CE to SQL Server Express or higher is pretty much a button click. The file size limit is 4GB at the moment, but Microsoft are looking to increase that.

There's a lightweight IDE, which in the Beta1 seems very easy to use (although quite limited in functionality at this stage), and the whole package weighs in at about 15MB (assuming you already have .NET 4.0 and MVC 2 installed). Intellisense is not included in the Beta1, but is promised in future versions.

The editor provides support for more than just ASP.NET. You can create sites using classic ASP, PHP (although support for PHP is not provided out-of-the-box with IIS), Web Forms (aspx) and the new Web Pages model (.cshtml or .vbhtml), which use the newly introduced Razor syntax. Other features include the ability to create sites from downloadable templates, such as Joomla, DNN, WordPress etc, and a wizard helps users to configure these as required. WebMatrix will identify, download and install any prerequisites, such as databases etc as part of the configuration. The Beta includes a limited selection of pre-built templates for a Starter site, a database driven product (bakery) site, a link collection site and a photo gallery site, but I suspect that more will follow.

One of the most interesting things by far is what WebMatrix helps to tell us about the roadmap for ASP.NET MVC 3, particularly in the areas of task-based helpers and the new View Engine. WebMatrix includes a host of simplified helpers for things like Captcha, email, caching, working with images, media, grids, charts and more. Want a Twitter feed in your page? How easy is this?

A new Membership provider is introduced to work with the new database platform: SimpleMembershipProvider, which gives the developer a lot more control over what tables are produced and where. You can simply point it at your own database, and have the tables generated there. The API is slimmed down to the bare essentials, and just the 4 tables are added. While it has been simplified, it includes one new feature - the ability to manage account verification via email, which has long been waited for.

The View Engine within WebMatrix for the Web Pages model revolves around the new Razor syntax, which is based on C#, but includes support for VB. It may at first glance look like inline PHP or ASP-style scripting, but because it is fundamentally C# (or VB) it is strongly typed. If you have ever used the Brail or Spark view engines, the following snippet will not appear too dissimilar in structure:

Inline expressions are denoted by the @ sign. Code blocks are identified by surrounding them with curly braces: @{... } (or @Code... End Code for VB-ers). A similar concept to NVelocity Layouts is introduced to provide for a MasterPage alternative, and RenderPage and RenderSection helpers provide support for reusable partial content.

Data Access within Web Pages is provided by a new Database class, which has simple methods such a Query(), Execute(), GetLastInsertId(), QuerySingle() etc, and wraps query results in a strongly typed collection which gives users the benefit of working with properties instead of getting field values by index. It all works like a very lightweight LINQ to SQL. Standard SQL syntax is used to form queries, which is probably a good idea as newcomers are going to be able to find samples they can work with all over the Web. You can even use LINQ to SQL or the Entity Framework with Web Pages, but there is no tooling to support this.

The initial experience with WebMatrix is an all-code one. There is no design view, but then again, there is no tool box full of controls to be dragged onto one. Having said that, I've always been an advocate of the fact that the best view of your designs is the one you (and your site visitors) get in a browser. Getting the current page to appear in one is just a question of hitting F12, or clicking the Launch button. At the time of writing, there was no official word on whether a design view will be included in a future milestone. Having said that, Web Pages will be supported by Visual Studio, so any WebMatrix IDE limitations can be nullified.

I make no secret of the fact that I am not a fan of Beta products, but I found WebMatrix easy to install, and it worked straight out of the box. I've really enjoyed playing with it over the last week or two, and suspect that it will be very popular with people who find Web Forms or MVC daunting at first. They will find the new Web Pages model a lot easier to work with. Web Pages, if anything, is more like MVC in that it takes the user a lot closer to bare HTTP and HTML than Web Forms, but is a lot easier to understand than the MVC model. The helpers do an awful lot to abstract away some unnecessary (for beginners) plumbing such as ADO.NET, System.IO etc, and the User Control/Master Page/Partial View model is nicely managed with something more like classic ASP include files - all with the benefit of strong typing and the full power of the .NET framework behind it.

With this launch, it seems to me that Microsoft have finally understood that Web Forms is not an easy introduction to web development. WebMatrix competes head-on with the easier-to-use WAMP stacks, and is likely to make inroads in the all-important college and school sector, undermining the OSS community's strangle-hold there. But if this is the way that school kids are going to be introduced to ASP.NET, the next logical step (when they grow up) will be MVC. So where does that leave Web Forms as a paradigm? Microsoft insist they are still behind web forms, and are continually adding "goodness" in that area. However, if you look at the advances made in .NET 4.0, all that was really on offer to the web forms community were some improvements which tackled long standing existing problems - nothing really "new". Web Forms is still a relatively easy "in" for desktop developers looking to break into web development, but WebMatrix is a much more natural web development paradigm. I suspect at some stage, Web Forms will end up being referred to as "classic ASP.NET".