ASP.NET 4.5 New Features

ASP.NET Web developers need to understand Visual Studio, NuGet , ASP.NET and Windows Azure for developing cloud services. Visual Studio 2012 has some cool improvements for web development.This article outlines the HTML5 and CSS3 improvements in the Visual Studio editor, Page Inspector and new features in ASP.NET 4.5. Using Visual Studio 2012 you can now write HTML, JavaScript, CSS and Razor, C# and VB applications. If you are more interested in knowing what is new in WebForms 4.5 then you can read this article.

The following show the tools and frameworks required for the ASP.NET Web Development:


NuGet is a package manager, it is how you bring your dependencies to your project. This is a fundamental thing that ASP.NET web developers should know and use. The ASP.NET 4.5 Framework is as in the following:


Using this framework, you should be able to create web sites and web services. You have web forms for control-based or event-based development. Web pages for very light PHP style pages using the Razor syntax. You also get MVC and the Web API. SignalR that you can use for real-time communication. Using this framework you can develop HTML5, HTTP Services , APPs for office, Mobile Applications and real-time applications using web sockets.

Model Binding with ASP.NET Web Forms

Using Strongly Typed Data Controls, you can set ItemType for a data control on your page and then in the page you will get intellisence and type checking.

The following sample shows setting the item type for a data control:

  1. <ul>  
  2.     <asp:Repeater ID="productRepeater" runat="server"  
  3.           ItemType="WebApplication3.Models.Product">  
  4.    </asp:Repeater>  
  5. </ul> 
The following sample shows referring to the properties using the Item keyword:
  1. <ul>  
  2. <asp:Repeater ID="productRepeater" runat="server"  
  3.    ItemType="WebApplication3.Models.Product">  
  4.  <ItemTemplate>  
  5.     <li>  
  6.       <a href="ProductDetails.aspx?Id= <%#: Item.ProductID%>">  
  7.        <%#: Item.ProductModel %> <%#: Item.ProductCategory %>      
  8.        </a>  
  9.      </li>  
  10.    </ItemTemplate>  
  11. </asp:Repeater>  
  12. </ul>
The following sample shows model binding getting the data:
  1. <asp:Repeater ID="productRepeater" runat="server"  
  2.   ItemType="WebApplication3.Models.Product"  
  3.   SelectMethod="productRepeater_GetData">  
  4. </asp:Repeater>
The select method code is as in the following:


You tell your repeater control about your select method and it returns an IQueryable. It is a simpler way to bind the data to your controls especially when you are a repository pattern that contains Create, Update and Delete methods.

WebForms: Friendly URLs

Friendly URLs in WebForms use the same routing system in MVC and also use the control binding.


Bundling and Optimization

Web pages have external references like CSS, JavaScript and Images. Bundling combines the CSS and JavaScript requests, for example if you have 5 CSS files it will then bundle them into one CSS file. Minification is the process of compressing the bundled files.

It removes the white-space and it changes the values of your variables and it also removes the comments. The convention is , if you have a file foo.js then after minification the file has the name foo.min.js. You will see the BundleConfig.cs file under the App_Start folder.

The EnableDefaultBundles method will bundle all js files and folders like scripts. You can also add various kinds of static bundles as in the following:
  1. bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").  
  2. Include(  
  3. "~/Scripts/WebForms/WebForms.js",  
  4. "~/Scripts/WebForms/TreeView.js",  
  5. "~/Scripts/WebForms/WebParts.js"));  
You can also do the dynamic bundling by adding your own folder name that would not be shown in your physical location by adding all the required files from the include directory, as in:
  1. bundles.Add(new ScriptBundle("~/Scripts/Virtual""*.js").IncludeDirectory("~/Scripts/bundle""*.js"));
The folder virtual does not really exist. You can also do the dynamic bundling using CoffeeScriptCompiler and IBundleTransform and you need to override the process method as in the following:
  1. bundles.Add(new DynamicFolderBundle("coffee""*.coffee"new CoffeMinify()));  
CoffeMinify is a custom class that does the minification for JavaScript files using CoffeeScriptCompiler; see:
  1. using System.Web.Optimization;  
  2. using SassAndCoffee.Core;  
  3. using SassAndCoffee.JavaScript.CoffeeScript;  
  4. public class CoffeMinify : JsMinify  
  5. {  
  6.     public CoffeMinify() { }  
  7.     public override void Process(BundleContext context, BundleResponse response)  
  8.     {  
  9.         response.Content = new CoffeeScriptCompiler().Compile(response.Content);  
  10.         base.Process(context, response);  
  11.      }  
  12. }
Page Inspector

Page Inspector works with Websites, Web forms and MVC. You can use Page Inspector by right-clicking on a .aspx page or through the browser menu. See:



It opens an integrated browser inside the Visual Studio, on the lower left corner you will get live DOM source editor. When you hover on the element it then shows you the element that you are inspecting and if you want to see what made that element then click on Inspect as in the following:


ASP.NET and HTML5 works together and more on this topic can be read here and Web Forms 4.5 features can be read here.

Similar Articles