A short introduction to ASP.Net Web Pages,Webmatrix and Razor

I wanted to write a few thoughts of mine regarding the new lightweight development tool available from Microsoft called WebMatrix.

It can be installed side by side with Visual Studio 2010 and Visual Web Developer 2010 Express.

In order to download WebMatrix click here . You download the Microsoft Web Platform Installer and through that Installer you install the WebMatrix.

There is no point for me to show you the installation process. It is very easy and you can have a look at this post to see the actual screenshots.

The main site for the WebMatrix is this one.

Scott Gu in one of his posts introduced WebMatrix. If you want to have a look at the post click here.

In the same post you can find links for the IIS Developer Express, SQL Server Compact Edition and ASP.Net Razor engine

So basically WebMatrix is a develpment tool-platform-stack that contains a number of things such as

  • The new Razor template engine
  • ASP.Net web pages - their name for the .cshtml and .vbhtml pages enhanced by the Razor view engine
  • IIS Express
  • SQL Server Compact Edition

So basically we can use the WebMatrix to create web applications. We have also the possibility to install popular open source web apps like DotNetNuke,Kentico e.t.c.

We can of course build ASP.NET Web Pages using Notepad ( I strongly advise against it ), Visual Web Developer 2010 Express Edition or any version of Visual Studio 2010. 

Microsoft thought that they needed to create a very simple tool that removes much of the features of Visual Studio that you may not need to publish a simple web site.  The name of the tool is WebMatrix. 

The truth is it looks very different from all the other developer tools you have come across. From this tool you can type in HTML and C# or VB, you can create and edit a SQL Server Compact Edition database, test the site (against IIS Express, more about that later), and publish to a host. I know a lot of people, web enthusiasts, beginners that get a bit confused with Visual Studio UI.  There are big (MS office, ribbon) like buttons and I doubt a tutorial would even be necessary.

So let's dive into ASP.NET Web Pages. My first impression was "Welcome back to 1999!!!!". I was a junior web developer at the time in London ( working for a small software house ) creating web apps with classic ASP. Yes, spaghetti code!!! VBscript integrated with HTML.

One would argue, that one of the basic reasons people move away from classic ASP was exactly that. They wanted to have cleaner-neater code. Well ASP.Net Web pages are somewhat like classic ASP.

There are important differences

  • It has a much cleaner syntax for poking data into HTML
  • A very easy way of integrating basic CRUD operations into the pages
  • Many Helper classes that help us to do basic web operations such as ( upload images,silverlight video )
  • We can call popular features from ASP.Net Web forms like Membership and Authentication

One might ask, I have been spending lots of time learning LINQ. Can I use Linq queries with asp.net pages? the short answer is no, but it is still early days.

So the question remains why to use this new framework?. I am sure that we all realise that Microsoft has its reasons to do introduce us to this new web framework.

We already have ASP.Net web forms and ASP.Net MVC. This new framework did not come to replace existing/established ways of creating web apps.

One explanation is that there are a lot of people who still write classic ASP. For some reason they were convinced to make the switch. Microsoft know hopes to bring them to the .Net world.

 So the people Microsoft targeting are

  • Php developers - They cannot say that the LAMP stack is free while in the MS world there is nothing free. You do not need to pay anything to build a web app in the MS world
  • Classic ASP developers
  • students/beginners

If you are a more experienced developer with a small web project to implement you should also consider WebMatrix.

A few more words for Razor.
Razor is a "view engine" that will be shared by ASP.Net web pages and ASP.Net MVC. The Razor syntax is based on the C# programming language. Most of the samples available are in C# but VB is supported.

You do not have to use <%= %> to insert data into the HTML.  Think of it as a better templating system with a more convenient character sequence.  To poke in a value from a helper method, your model (MVC) or a variable (ASP.NET Web Page) you can use the @ symbol.  To insert a block of code into your page, use @{  

You can find a comprehensive tutorial here .

I will write more posts on ASP.Net web pages and how to perform simple programming tasks.

Hope it helps!!!

No Comments