Programming Microsoft ASP.NET 4 - Dino Esposito [15]
ASP.NET Web Pages
ASP.NET Web Forms was relatively easy to embrace for developers and software professionals. ASP.NET MVC requires a bit of extra work and doesn’t really lend itself to being learned and discovered on a trial-and-error basis. So how high is the barrier to get into the world of ASP.NET?
ASP.NET Web Pages offers a new approach. ASP.NET Web Pages is not a framework aimed at professional developers, but still it is part of the ASP.NET platform and will be updated in the future. Let’s find out more.
Small, Simple, and Seamless
ASP.NET Web Pages targets an audience of Web developers who are involved in very simple projects either because they’re not software specialists or because the site to create is extremely simple indeed. This audience would benefit from even further simplicity such as a single page model and a simplified way of writing code and the view. ASP.NET Web Pages comes with a new IDE called WebMatrix and a simplified version of IIS, aptly named IIS Express. WebMatrix, in particular, wraps up server code, markup, and database tables in a new designer environment that makes it a snap to write pages and publish them to a site.
Code and View Together
With ASP.NET Web Pages, you write pages using a mixed syntax that incorporates both markup and code, but in a way that is a bit cleaner than today with either Web Forms or ASP.NET MVC code blocks. By using the @xxx syntax, where xxx is a built-in object, you can insert in the markup some dynamically calculated value and also use those components to emit ad hoc markup. Here’s an example:
Today is @DateTime.Now
Such objects are more similar to ASP.NET MVC HTML helpers than to Web Forms controls, and they represent dynamic code you can interact with in a single environment while building the output you expect.
Note
The syntax supported by ASP.NET Web Pages (formerly codenamed Razor) is the new default language for defining views in ASP.NET MVC 3.
Summary
ASP.NET Web Forms is the Microsoft premier platform for Web applications. It was originally designed a decade ago to fit as closely as possible the skills and needs of the average developer of the time. Ten years ago, the typical developer was either a former C/C++/Java developer or an early adopter of HTML willing to do fancier things that JavaScript could just not support. In the middle, there was the Visual Basic developer, accustomed to RAD programming and slowly absorbing the basic concepts of object-oriented programming. ASP.NET Web Forms was designed for these developers. And it worked great for several years. Now, however, it is showing some clear signs of age.
The advent of AJAX revolutionized the perception of a Web application and sparked a paradigm shift—a long process that we have probably gone through for no more than 70 percent of its natural length. Web Forms is really close to its architectural end. If you lead a team of developers, and if your business is based on ASP.NET and Web applications, you should make sure that the framework of choice will take you just where you want and do it comfortably enough.
In the past years, the number of Web applications (including simple sites) has grown beyond imagination. As a developer, you might be asked to design and build anything from a simple site with just a small collection of data-driven pages up to the Web front end of an enterprise-class application, where scalability, extensibility, and customization are high on the priority list.
Is Web Forms up to the task? Sure it is, but you should consider that the conventional way of working of Web Forms doesn’t lend itself very well to creating testable code, mockable views, and layers. Web Forms is essentially