Microsoft WebMatrix – Easy way to build ASP.NET Web Sites

Yesterday Microsoft announced WebMatrix, a tool to build standalone ASP.NET Pages using the new Razor view eninge. With WebMatrix developers will get the new IIS Developer Express and SQL Compact Edtition.

The idea of WebMatrix is to make it easy for developers to build web sites, not yet suitable for Enterprise Apps in my opinion, more for devs that want to get started really fast. With WebMatrix we will get a tool to easily create a Site, Browse our files, manages our database etc:

image

The tool is easy to use, easy to learn and manage. You don’t need to have Visual Studio to create a simple ASP.NET website. The following is an image editing a file within the tool:

image


Razor is a new View engine which can be used to write ASP.NET Web pages, the "Razor" view engine together with WebMatrix reminds me a lot about classic ASP pages but using .Net, something that I like. It will make it much easier for those devs that find it hard to move from classic ASP to ASP.Net. Here is an example why I think WebMatrix and "Razor" reminds me of classic ASP pages, the code will read from a database and list members that belongs to a specific group, the value of the group is taken from the QueryString “group” by using the Request helper method:

@{
   string group = Request[“group”];
   var db = Database.Open("Members");
   var members = db.Query("SELECT * FROM Members WHERE Group = @0", group);
}

<html>
      <head>
               <title>List members</title>
      </head>
      <body>
                <ul>
                   @foreach (var member in members) {
                      <li>@member.FirstName - @member.LastName</li>
                    }
                 </ul>
      </body>
</html>

I like this way of writing a small app and the Razor’s much cleaner syntax. Have in mind that Razor view engine with ASP.NET MVC can be used for enterprise apps. Using Razor with WebMatrix will not target entperise apps developers in first place.

Handling “submit “ HTTP Post and also caching is quite easy. To check if a Post is made, we can use the IsPost property, to cache information we can use the WebCache helper, the following is just a fast example I put together to demonstrate the use of IsPost and WebCache helper,

@{

     var minutesToCache = 10;
     var useSliding = true;
     string data = string.Empty;

     if(IsPost)
     {
           data = Request["myData"];

           if (WebCache.Get("Key") == null)           
                WebChache.Set("Key", data, minutesToCache, useSliding);
     }

    if(WebCache.Get("Key") != null)
          data = WebCache.Get("Key").ToString();
 }

<html>
      <form ..>
           <input type="text" name="myData" value="@data" .../>
           <input type="Submit" ..../>
      </form>
</html>

With Razor we will get some social Web Helpers, for example Twitter, Gavatar etc:

<body>
      @Twitter.Search("WebMatrix")
</body>

We can also an easy way create Code-based helper method, Microsoft is looking for supporting HTML Helpers, to globally share helpers among pages. Here is an example of a HTML Helper (will not work in the beta):

@helper RenderMembers(List<Member> members) {
   <ul>
      @foreach (var member in members) {
        <li>@member.FirstName @member.LastName</li>
      }
   </ul>
}


<body>
    @RenberMembers(Model.Menbers)
</body>

If you want to know when I have published a new blog post, follow me on twitter: fredrikn

3 Comments

  • Vad är det som gör att det påminner dig om klassisk ASP? Mig veterligen så levde man även då i världen. Razor handlar väl inte om att placera kod i vyerna oavsett som det är mvc eller webforms.


  • @Knecke asked me why "Razor" reminds me about classic ASP, so I will try to explain it with a short comment:
    "Razor" is a new view engine, so it's the way writing pages with the Razor view engine that reminds me about classic ASP pages.
    When using "Razor" view with MVC, there will not be any server-controls and event-driven programming, "code-blocks" as in classic ASP will be in the view, but Razor is using a much cleaner and better expression and syntax. Nothing wrong at all, I love it it will give us better control over the HTML. The View in MVC should only have code that presents the model, nothing more, the rest of the logic is part of the controller and is more sutiable for enterprise apps.
    When using "Razor" with WebMatrix:
    WebMatrix is all about writing simple web apps where "code-blocks" will be added to the view as in classic ASP by using Razor, and using helper methods that will be similar to classic ASP includes. It's perfect for small apps, and also apps that needs to handle changes fast.
    When I'm say classic ASP, I'm thinking about HTML mixed with code-blocks.. instead of using server-side controls and code-behind.

  • Isn't this why we have 'Developer Express' ?

    I don't get it

Comments have been disabled for this content.