Building an ASP.NET Framework Website Using WebMatrix

Introduction

WebMatrix is a light weight tool released by Microsoft to facilitate the development of a website at a rapid pace. If the .NET framework 4.0 is not installed on the machine then the WebMatrix installation will also download and install the .NET framework for you.

You can download the WebMatrix tool from here.

Below are listed the notable features of WebMatrix:

  1. Rapid development of ASP.NET websites. The reason why I say this is it provides sections like website gallery and site templates. The website gallery constitutes a set of pre-built open source websites by third parties like WordPress, BlogEngine.net, etc. You can simply extend or customize these websites as per your needs. This drastically reduces the development time and effort.
  2. It supports the development of standalone ASP.NET Web pages which can blend Razor and HTML. Their extension is .cshtml/.vbhtml.
  3. It provides support, from Development to SEO optimization and Deployment.
  4. It allows the creating of databases and using them in the websites.
  5. It can be used side by side with Microsoft Visual Studio IDE.

This tool can facilitate the building of personal websites quicker and easier. It can be very useful for the people who are thriving to step their feet into the ASP.NET development world.

The limitations are:

  1. You cannot create an .aspx.cs file or write any server side code. I would say this limitation can very well be overcome by using Microsoft Visual Studio for writing the server side code. In the tool there is also a provision to open the website in Microsoft Visual Studio
  2. No intellisence

The WebMatrix tool includes a development web server called IIS Developer Express. This development web server can host the website dynamically when the run button is clicked. So a developer can see the output of the pages instantly.

The SQL Server Compact Edition, included in the WebMatrix tool, enables database development for websites built using WebMatrix. Fig 1.0 shows the default landing screen of the WebMatrix tool.

default landing screen of the WebMatrix tool
Fig 1.0

Website Options

In this section I will take you through the various options available for creating a website. As you can see in Fig 1.0 there are three options.

  1. Site From Web Gallery
    There are many open source prebuilt websites which are integrated into the Web Gallery. The developer can choose the website from the gallery and it will download the entire website from internet. It can be used as it is or can be customized as required. The main difficulty while developing a website for ASP.NET developers is to construct the website flow, design the web page and provide a uniform style across the site. This task also consumes most of the development time and effort. Such a scenario can be overcome by making use of these existing open source websites in the web gallery section. Fig 2.0 shows the list of categorized websites available on the web gallery section.

    list of categorized websites available on the web gallery section
    Fig 2.0

  2. Site From Template
    There are also templates available which you can have as a base for developing the website. Below is the list of templates available with WebMatrix currently.
    • Empty Site
    • Starter Site
    • Bakery
    • Link Directory
    • Photo Gallery
  3. SiteFromFolder

In case you need to develop on top of the website which is available on your local file system then you can make use of this option. This option allows you to select the website from a local folder. Fig 3.0 shows the website folder selection popup.

the website folder selection popup
Fig 3.0

Developing a Simple ASP.NET Framework Website

In this section we will develop a simple website from the "Empty Site" template which will also make use of the data from a SQL Server Compact edition database. Before getting into the development check the screenshots in Fig 4.0 and 4.1 for the option available for development of ASP.NET Web Pages and databases.

development of ASP.NET Web Pages
Fig 4.0

Create a database named MyDatabase.sdf. Now add add a table to MyDatabase and name it as Customer. Fig 4.1 shows the database section of the WebMatrix.

database section of the WebMatrix
Fig 4.1

Add few sample records to the Customer table. In the website we will create a .cshtml file to our website called FirstWebPage.cshtml. In the web page we will use the combination of Razor and HTML to display the customer list.

Below is the FirstWebPage.cshtml code:

  <!DOCTYPE html>
  @{
      var database = Database.Open("MyDatabase");
      var customers = database.Query("SELECT * FROM Customer");
  }
  <html>
      <head>
          <title>Customers Page</title>
      </head>
      <body>
          <h1>Your cusomers are listed here:</h1>
          <table>
              <thead>
                  <tr style="background-color:Black;Color:White;">
                      <td style="font-weight:bold">Customer ID
                      </td>
                      <td style="font-weight:bold">Name
                      </td>
                      <td style="font-weight:bold">Age
                      </td>
                  </tr>
              </thead>
              <tbody>
                  @foreach(var customer in customers){
                  <tr style="background-color:Silver">
                      <td>@customer.CustomerId
                      </td>
                      <td>@customer.Name
                      </td>
                      <td>@customer.Age
                      </td>
                  </tr>
                  }
              </tbody>
              <tr>
                  
              </tr>
          </table>
      </body>
  </html>

Click on the Run button in WebMatrix. Fig 5.0 shows the output on the browser.

the output on the browser
Fig 5.0

Conclusion

I hope this brief article got through the various ASP.NET framework website development aspects available on WebMatrix. Even though the demo site is very basic I trust that it has served the purpose. In my next article I will be covering the Search Engine Optimization and deployment of ASP.NET framework website using WebMatrix. I have attached the source code that we created.

Happy reading! See you in my next article.

Related Article



About the Author

V.N.S Arun

I work for an MNC in Bangalore, India. I am fond of writing articles, posting answers in forums and submitting tips in dotnet. To contact me please feel free to make use of the "Send Email" option next to the display name.

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds