How WebMatrix, Razor, ASP.NET Web Pages and MVC fit together

Today, we announced the public availability of the Microsoft WebMatrix Beta.  This is an exciting time, as we’ve been working on this project for quite a while, and have been eager to get it out there!  Our VP Scott Guthrie has been blogging about a number of its components in the last week or so, and you should definitely read through his posts to get a lot of information about it (start here).

In this post, I’d like to discuss how various pieces fit together, as I’ve seen some amount of confusion in the early user comments that I have read.  Note that I’m not going to describe the pieces in much details (again, see ScottGu’s blog for this).  Instead, my focus is on clarifying the relationship between some of the pieces.


WebMatrix: a stack and a tool


Let’s start with WebMatrix.  The term is actually used is two ways:

  1. The WebMatrix stack contains a number of things that you get when you install it via WebPI:
    • The new ASP.NET Web Pages framework
    • The Razor templating engine
    • The WebMatrix tool (see #2)
    • IIS Express
    • SQL CE 4
  2. The WebMatrix tool, which lets you perform various tasks:
    • Create web apps that use the Web Pages framework and the Razor templating engine
    • Install existing sites from the Web Gallery.  Note that those sites don’t have to use the Web Pages framework, and in fact most don’t (e.g. ScrewTurn wiki, Subtext)
    • Manage IIS express
    • Manage SQL CE 4 databases

Key point: the WebMatrix tool is not by any mean the only way to create Web Pages apps.  In fact, the Web Pages framework was designed to be very notepad friendly.  On the other end of the tooling spectrum, it will later be fully supported by Visual Studio.


Razor: a templating engine


At its root, Razor is just a templating engine, which is best compared to something like T4.  It is also comparable to the aspx and Spark engines.  The best way to describe it in its most general sense is:

  • It takes as input:
    • a template file (with a .cshtml or .vbhtml extension)
    • some input data: in web scenario, this includes things like an HTTP request, but this is not a requirement
  • It produces some output string: in web scenario, this is typically a piece of HTML that then gets sent as an HTTP response, but it could be anything.

So as an example, you could envision a very simple command line tool that would read an input file and some parameters, and write out the result of running the template on that input.  Note that everything I wrote here applies both to Razor and to something like T4.

Key point: Razor in itself is not tied to MVC nor to the Web Pages framework, and is not even really tied to web applications.

Note: check out Andrew Nurse’s blog for lots of technical details about Razor.


ASP.NET Web Pages: a simple framework to write ASP.NET web apps


WebMatrix introduces ASP.NET Web Pages, which gives users a simple and powerful new way of writing ASP.NET apps.  It is different from WebForms as it doesn’t use server controls.  It is also different from MVC as it doesn’t follow the MVC pattern.  Instead, it follows a much simpler ‘inline page’ model, where a page is basically an HTML page with some code added where needed.  In that sense, it is reminiscent of Classic ASP, but it is also very different in the sense that it has the full power of the .NET framework available behind it.  It also supports concepts like layout pages which make it much more flexible than the Classic ASP.

Where the discussion gets interesting is that the Web Pages framework uses Razor as its default templating engine.  However, it is not tied to Razor.  Potentially, you could use the aspx or Spark templating engines with the Web Pages framework.  At this point, we have mostly focused on using Razor with it, but it’s entirely conceivable that other templating engines would be supported later.

Key point: ASP.NET Web Pages uses Razor by default, but is not technically tied to it.




ASP.NET MVC is not part of the WebMatrix release, as it is a completely different framework with different goals (and this post is not about the pros and cons of the two, so I won’t go into that here!).  However, it ties into the story because the Razor templating engine will (soon) be made available as an MVC view engine.  As it should now be clear, this does not imply that you would be using ASP.NET Web Pages if you choose to use Razor as your MVC view engine.  All it means is that you’d be using the Razor syntax for your views instead of aspx (or Spark, …).  This has no bearing on how you write your controllers or other parts of your app.

Key point: Razor syntax will soon be available as an MVC view engine alternative.




Hopefully, I have been able to clarify how some of the pieces that come with WebMatrix fit together.  Please leave a comment if you have any questions and I’ll try to clarify further!

Comments (15)

  1. Rasel Jabbar says:

    Thanks for clearing that up 🙂

  2. infocyde says:

    I played with cshtml a lot today, I dig it.  For simple stuff it is really cool, reminds me of the simplicity of the good old classic ASP days.  I'm sure I will try to push it and get frustrated, but what else is new?  For now cshtml/razor/Compact SQL are my buddies.  

    I know it is all really targeted at rockies and PHP devs, not really .Net pros, but the new tech still might lure me into using razor and expecially Compact SQL for a lot of small to midsized projects once it gets out of beta.

    Cool post, I like the text blogs and then the key points, makes it easy to skim, which is good in an ADD world.

  3. M B says:

    I am sorry to leave a comment here instead of the page this question is for, but it seems I'm unable to post comments there (perhaps the post is too old?)…/creating-a-controlbuilder-for-the-page-itself.aspx

    I am curious as to how to do both instance (i.e. the instance of the control in a parent page) processing as well as type (i.e. the ascx file that defines the control) processing.

    It seems that having both a ControlBuilder as well as a FileLevelControlBuilder doesn't do the trick, and using just FileLevelControlBuilder seems to only process the definition ascx file.

    Thanks in advance!

  4. David Ebbo says:

    M B: sorry about that, it was an issue with my blog settings.  You should be able to comment on the right post now.

  5. Thanigainathan says:


    This is very nice article.



  6. Mimi says: engine accepts cshtml can render the templates directly. Through a WSIYWYG approach. However, when you put silverlight xaml objects together in the same page (for the beta) it doesnt render!

  7. Géza Mikló says:

    For a beginner this is a stunning new thing with quick success. It is definitely a good stack, but in my opinion people working aorund the web should be forced to build cleaner codes.

    The same thing is true for PHP. If you want to build clean, well structured code, you can. But the more freedom you give coders to mix things up the worse strutured codes will spread around the net. I saw a lot of examples on that.

    Coding standards binds your hands at first, but when you have to deal with the same code after a year, you will still be able to understand it quickly.

    Freesom is good also, but deal with it wisely 😉

    Nice work either! Congrats!

  8. Mike Simpson says:

    Thanks for this useful comparison.  Could you add some info about Lightswitch?  Both Lightswitch and WebMatrix seem to be aimed at a simpler, quicker development experience, which begs the question of how to distinguish them.

  9. David Ebbo says:

    @Mike: this post is more about clearing up the naming confusion than about helping choose which technology is right for a given task, which is a bigger topic. Also, I'm not a Lightswitch expert, so I'm probably not the best person to answer this 🙂

  10. Jason says:

    @Mimi, I tried the mapjects engine, looks like this more for data visualizations and operational views. Can you show me how to WSIYWYG the dynamic rendering into the template, they need to put some documentation out to the public… but I love it.

  11. Georges says:

    Waht about a description on the pros/cons?

  12. David Ebbo says:

    @Georges: has some good Getting Started info. This post is more about clarifying the naming of the pieces.

  13. MVC and native HTML with Mapjects extension says:

    Jason, we're using the Mapjects engine too for the data harvesting or GIS data sets with Mapjects clinical sunshine engine, wondering if you can provide some feedback on the Mapjects indexers

  14. says:

    To ensure you keep your assets organized and bundled, we use it works well in tracking any kind of assets and updates to the assets in the build cycle