InfoWorld preview: Microsoft WebMatrix ramps up ASP.Net development

WebMatrix combines excellent all-in-one installation, gallery of templates, and coding shortcuts to speed the development, deployment of Windows-based websites

WebMatrix is Microsoft's new easy on-ramp to the busy Web development freeway. With WebMatrix, you can create, execute, and deploy Web applications in an environment that is ridiculously easy to install and use. WebMatrix rolls up all of the components needed to build and run Windows-based websites, and provides a number of aids that help streamline the development process. Combining simplicity with standard tools, it will be attractive to both budding and experienced ASP.Net developers, and to anyone who wants to build a website that he or she is sure will remain small. 

Currently a beta 2 product, WebMatrix can be downloaded via the Microsoft Web Platform Installer at Microsoft's website. The platform installer not only installs WebMatrix, but gives you the option of fetching Visual Web Developer 2010 Express and SQL Server Express 2008 R2. WebMatrix itself consists of an IDE (within which you create, manage, and deploy websites), IIS Developer Express (a lightweight version of Microsoft's application server), and the SQL Server Compact database engine.

[ Keep up with software development issues and trends with InfoWorld's Fatal Exception blog. | Follow the key developments in Microsoft and Windows technology with InfoWorld's Technology: Microsoft newsletter. ]

This final component is a file-based version of Microsoft SQL Server -- and, therefore, not a server at all. As with the other parts of WebMatrix, SQL Server Compact is small-scale: fine as the embedded database for a single application, but too limited for large applications. According to Microsoft's documentation, the database file can be no bigger than 4GB and allows no more than 256 connections. Additionally, it won't recognize all the data types that a full SQL RDBMS does.

WebMatrix code helpers and templates When first launched, the WebMatrix IDE opens the quick-start page where you can select an existing website or build a new one. New sites can be constructed from scratch, imported from an existing site, or built from a template drawn from WebMatrix's site gallery. At the time of this writing, the gallery boasted 34 templates in categories such as blogs, CMS, and e-commerce. Well-known website systems were available, among them: Drupal, moodle, DotNetNuke, WordPress, and phpBB.

Although WebMatrix does have some PHP support, the product is decidedly pro-ASP.Net. The view engine promoted by WebMatrix is Microsoft's Razor, which sits atop the ASP.Net MVC (model-view-controller) framework. WebMatrix silently installs ASP.Net along with IIS.

Razor makes it easy to script HTML pages with server-side C# or VB.Net. (Files with mixed HTML and Razor code have the CSHTML extension.) Plus, Razor gives access to a boatload of encapsulated functionality in the form of "code helpers."

Under the hood, a code helper is really a public static .Net class whose exposed methods are available to the Razor engine. You can invoke a helper with a single line of code. For example, @Facebook.LikeButton() will render the familiar Facebook Like button on a Web page. Microsoft already provides helpers for displaying data in a grid, validating user input in a page form, handling file uploads, managing video and audio, sending email, analyzing traffic on your website, and lots more.

While Razor's "inline coding" style, which mingles business logic with view code in one file, might seem a step backward, Razor supports a kind of templating in which you define content pages apart from layout pages, separating static content and display mechanics. Consequently, a single layout definition can be applied to multiple Web pages.

This scheme works with the help of the LayoutPage property. At the outset of a content page, you include a bit of Razor code that looks like:

This effectively binds a content page to its layout page. The layout page (typically stored in a shared folder) is also a CSHTML file, but is shot through with the HTML that specifies a page's visual structure, mixed with Razor rendering functions that fetch and incorporate the appropriate content from the content page. You might have this bit of HTML code in the layout page:

Meanwhile, in the initial Razor code of the content page, you'll find this:

The content page will also identify named sections, which are instantiated in their proper location (and style) by the layout page, with the assistance of the @RenderSection() Razor function.

The upshot is that multiple Web pages (content pages, in this case) use a single layout page, which not only imparts a consistent look and behavior to the pages within a layout group, but also promotes reuse by gathering layout code into a single file. In addition, the layout page can flexibly accommodate either the presence or absence of named sections among the content pages it services.

WebMatrix database workspace and deployment Another important website ingredient is a back-end database. Just choose the database workspace in the IDE, define a new SQL Compact database for your site, and WebMatrix provides tools for creating a new table, modifying the schema of an existing table, viewing and editing a table's data directly, managing indexes, or issuing an SQL query against the database. As with other parts of WebMatrix, the IDE's database capabilities will get you started, but carry you only so far. It has none of the advanced features (such as user management) you'll find in full RDBMS management tools, but is sufficient for SQL Compact.

WebMatrix provides multiple "workspaces" in which you manage different aspects of your website. For example, the files workspace lets you work with folders and individual Web page files. In the database workspace, you can create a SQL database, view database table data, or issue SQL queries.

Inline Razor code makes it easy to instantiate a database object, define a query, issue the query against the database, and iterate through the results for display on the webpage. (Or you can use that data grid helper mentioned earlier.) If SQL Compact gets too cramped, WebMatrix provides a migration tool for moving a Compact database to Microsoft SQL Server or SQL Server Express. All you need are the connection strings for the destination database; the migration tool replicates the schemas in the target and copies the data over.

Finally, WebMatrix also automates website publication. Not only can WebMatrix transfer your website's folder structure and files to your target server, it will also deploy your site's database. In addition, it produces an audit of the deployment for verification that all the pieces arrived at their destination.

WebMatrix publishes your site using one of two protocols: Web Deploy or FTP. Web Deploy is more automated, but only works with hosting providers that recognize it. Web Deploy also has the advantage of being able to deploy SQL Server or SQL Server Express databases; you enter the connection string and user access information for the target database, and Web Deploy will transfer tables and table content from your production server to the target. It also handles the chore of changing connection strings in your application from the production URLs to deployment URLs.

Meanwhile, FTP deployment is exactly what you'd imagine: It transfers files wholesale. While FTP transfer will work with any target site supporting FTP, it cannot deploy SQL Server or Express databases (though it has no problem with an SQL Server Compact database, which is just a file). And some of the behind-the-scenes work that Web Deploy does for you must be executed manually with FTP transfer.

WebMatrix haves and have nots Microsoft's WebMatrix website makes the following claim: "WebMatrix lets you code, test, and deploy both ASP.Net and PHP applications side by side." Well, yes and no. You can certainly code ASP.Net and PHP applications in WebMatrix -- in the same way that you can code applications in Notepad. Although the IDE does provide syntax highlighting, it has neither IntelliSense nor code-completion for any of the ASP.Net languages (Razor, C#, VB.Net) or for PHP.

WebMatrix does do a fine job of installing PHP-based websites from the site gallery, as I learned by installing the well-known phpBB bulletin-board system. WebMatrix found all the dependencies (I needed PHP for IIS, as well as SQL Express for the database), downloaded them, and built the correct folder structure. I was up and running in minutes.

As for testing applications, it's not pretty. WebMatrix has no debugger. There are a couple of helper objects -- ServerInfo and ObjectInfo -- that you can use to view important environment information and the data type and content of an object. But these are really nothing more than "debug by print" mechanisms. WebMatrix also has a Requests tool that captures the HTTP request/response traffic to your website. But the displayed information is severely abridged. You are not shown the raw data of the exchange, nor does WebMatrix display the HTTP headers, so this feature is only worthwhile for identifying which HTTP requests produced errors. If you have the excellent free Fiddler Web debugger installed, you'll never use WebMatrix's requests feature.

WebMatrix is a classic example of the whole being greater than the sum of its parts. The IDE itself is barely a glorified editor, there is no debugger, and the requests tracing system has marginal value. But SQL Server Compact is more than sufficient as a persistence system for small to moderate-size websites, the quantity and quality of instantly usable helpers are superb, and if you need to get started quickly -- especially if you can find what you need in the website gallery -- the installer is excellent.

WebMatrix's greatest strength is its scalability: start small, and build as you learn. You can create your website with only HTML, then use Razor to make it dynamic, and step into the world of code helpers. For a database, begin with SQL Compact, then move up to full-blown SQL Server. Finally, you can migrate the whole thing into Visual Studio and build all the server-side code in C# or VB.Net.

Also on InfoWorld:

This story, "InfoWorld preview: Microsoft WebMatrix ramps up ASP.Netdevelopment," was originally published at Follow the latest developments in application development and Windows at

Read more about developer world in InfoWorld's Developer World Channel.

This story, "InfoWorld preview: Microsoft WebMatrix ramps up ASP.Net development" was originally published by InfoWorld.

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2010 IDG Communications, Inc.

IT Salary Survey: The results are in