ASP.NET Web Matrix is a free, lightweight, easy-to-use Microsoft tool for developing ASP.NET Web applications. Web administrators can use the tool to build Web site—management applications, such as a Web application that lets you remotely monitor the health of your IIS Web farm. The Microsoft .NET Framework and ASP.NET Web Matrix make building Active Server Pages (ASP) applications significantly easier than other Microsoft tools do. If you've never tried ASP.NET, ASP.NET Web Matrix is a good place to start, with its WYSIWYG Web form designer, a set of tutorials, and links to the active ASP.NET community.
Getting and Installing ASP.NET Web Matrix
ASP.NET Web Matrix is a robust Web application builder with a variety of features, which Table 1 lists. You can download the 1.2MB ASP.NET Web Matrix at http://www.asp.net/webmatrix/download.aspx?tabindex=4. ASP.NET Web Matrix requires the .NET Framework and guides you through that tool's installation if necessary. (Note that ASP.NET Web Matrix also requires Microsoft Internet Explorer—IE—5.5 or later.) Links to download Microsoft Data Engine (MSDE—the free runtime version of Microsoft SQL Server) and Microsoft Mobile Internet Toolkit are also available on the ASP.NET Web Matrix download page. If you don't have SQL Server, you'll want to download and install MSDE so that you can build dynamic, data-driven applications.
After you download ASP.NET Web Matrix, installing it is simple. Double-click the webmatrix.msi file to execute the installation wizard. Agree to the free license and click Next a few times to move through the wizard. You have a choice of where to install ASP.NET Web Matrix, which requires 2565KB of drive space. Click Install to proceed with the installation and Finish to complete the installation.
ASP.NET Web Matrix Introduction
To run ASP.NET Web Matrix, click Start, All Programs, Microsoft ASP.NET Web Matrix. The program group includes ASP.NET Web Matrix, its documentation, and a .NET Framework ClassBrowser designed specifically for ASP.NET Web Matrix. The first time you launch ASP.NET Web Matrix, you see the Add New File dialog box. Click Cancel to close that dialog box, which you won't need until you build your first application.
Let's take a tour of the ASP.NET Web Matrix IDE, which Figure 1 shows. Across the top are the menu bar and standard toolbar. On the left is the Toolbox, a panel that contains a set of controls and tools that you can use while designing your Web application. The items available from the Toolbox are context sensitive and change depending on the view you're using.
The document window is the main work area in the middle of the IDE. ASP.NET Web Matrix dynamically creates the document window when you open or create a file. You use the view tabs—Design, HTML, Code, and All—at the bottom of the document window to move from one view of your application to another.
The Workspace window, on the top right, provides an organized view of your file system and open files (in the Works view) or MSDE and SQL Server data sources (in the Data view). In the Properties window, on the bottom right, you can see and edit the state, behavior, and appearance of an ASP.NET page, document, or control.
Building Your First ASP.NET Web Application
With ASP.NET Web Matrix running, select File, New to launch the Add New File dialog box, which Figure 2, page 8, shows. By default, ASP.NET Web Matrix creates an ASP.NET page, which is the file type that you want. Choose a logical location on a local drive to which to aggregate Web content, and give your new page a name. I created a folder called WebMatrix on my notebook and named my file TimTest.aspx. Make sure that the default programming language Visual Basic .NET is selected, and click OK.
ASP.NET Web Matrix creates the .aspx file for you and opens it in the document window in the Design view. My favorite feature of ASP.NET Web Matrix (and Visual Studio .NET, for that matter) is that it generates HTML for you. I'm not a big fan of HTML. Because HTML was never designed for the contortions we put it through in Web applications, writing it manually can be frustrating. So, I appreciate the ability to perform a couple of drag-and-drop operations to create a simple but functional Web application.
First, drag a Calendar control from the Toolbox's Web Controls section to the document window. Press Enter to go to the next line under the Calendar control. Drag a Label control (not visible in Figure 1) to the document window. Your document window should now look like the one in Figure 1.
Click the Label control in the document window, go to the Properties window, and delete the word Label in the Text property. Click the HTML tab at the bottom of the document window to view the HTML code that ASP.NET Web Matrix generated as a result of the two drag-and-drop operations. To modify the page, you can directly edit the HTML code in the HTML tab or All tab, or you can make changes in the Design tab.
Select the Design tab again. Double-click the Calendar control to automatically associate an ASP.NET server-side event-handler method with the control's SelectionChanged event and open the page in Code view. The event handler is named Calendar1_SelectionChanged. Add code in the event handler so that the subroutine looks like the following:
Sub Calendar1_SelectionChanged _ (ByVal sender As Object, _ ByVal e As EventArgs) Label1.Text = "You have" & _ " selected: " & _ Calendar1.SelectedDate() End Sub
A user who opens this page in a browser can click a date on the calendar to select it. ASP.NET calls the same page again with different parameters and displays the message "You have selected: day/month/year," where day/month/year is the day, month, and year the user selected. Click the Save icon on the toolbar to save the page. Then you can run the page.
Running the ASP.NET Page
The ASP.NET Web Matrix installation program installs a Web server that runs side by side with IIS if IIS is installed on your computer. Both Web servers run ASP.NET Web Matrix—built pages exactly the same way because the Web servers use the same ASP.NET runtime engine built on the .NET Framework.
To run the page you just created, select Start from the ASP.NET Web Matrix IDE's View menu, click the Start icon on the Standard Toolbar, or press the F5 key. You'll see the Start Web Application dialog box, which Figure 3 shows. To run the page in the ASP.NET Web Matrix Web server, make sure the default Use ASP.NET Web Matrix Server option is selected and click Start. The ASP.NET Web Matrix Server will start, and the page will run in a browser. Click a date on the calendar to see your ASP.NET Web application in action, as Figure 4 shows.
Notice that your computer's taskbar shows that the ASP.NET Web Matrix Server is running. ASP.NET Web Matrix doesn't ask you how to run subsequent pages after you've chosen ASP.NET Web Matrix Server and it's running. To run your page in IIS, you first need to stop the ASP.NET Web Matrix Server. Right-click the ASP.NET Web Matrix Server taskbar icon and select Stop. Return to the ASP.NET Web Matrix IDE and press F5. At the Start Web Application dialog box, select the Use or create an IIS Virtual Root option. In the Application Name field, enter a logical name for a virtual directory (e.g., WebMatrix). When you click Start, IIS creates a virtual directory and runs the page.
If you want to run the page under the ASP.NET Web Matrix Server again, you must exit ASP.NET Web Matrix. Then you must restart the program, load the page, and run the application.
A software-development revolution is happening—network and infrastructure folks and program, product, and project managers are using tools such as ASP.NET Web Matrix to build prototype and pilot applications that they then "throw over the wall" to developers. What a perfect story for building enterprise applications—actually enabling users to help scope projects through prototyping and piloting.
ASP.NET Web Matrix was built for single-developer Web application development. Unlike Visual Studio .NET, ASP.NET Web Matrix doesn't provide support for team-based development and doesn't support features such as IntelliSense (syntactical completion of words while typing) and debugging. The tool does provide a way to quickly start building ASP.NET applications that you can subsequently upgrade to Visual Studio .NET. Microsoft has promised to provide an upgrade wizard in future ASP.NET Web Matrix versions.
In a future article, I'll step you through more of ASP.NET Web Matrix's features. I'll also show you how to build an application that you can use as the basis of many data-driven Web applications.