New Features in ASP.NET 4.5

.Net Framework 4.5 came up with lots of great features. Writing about all of them will not be possible but I would like to add light on some features especially with regards to Asp.Net.

Microsoft's ASP.NET, one of the most successful web application development frameworks ever, is fast becoming mature – the newest version of it is ASP.NET 4.5. You can use ASP.NET to fast develop and deploy highly scalable, high-performance web applications in a managed environment. ASP.NET 4.5 ships as part of part of Visual Studio 2012 and contains many new and extended features. In this article we will discuss best features in ASP.NET 4.5 for developers.

Pre-requisites

Note that ASP.NET 4.5 ships with Visual Studio 2012. To work with ASP.NET 4.5, you need to download and install Visual Studio 2012 in your system.

Understand Asynchronous HTTP Modules and Handlers.

HTTP modules and HTTP handlers are two words we commonly hear from every Asp.Net developer. Many times we want to implement pre-processing logic before any web resource like image, text or aspx is requested. For example – We want to add a security check before actual page/resource processing starts.

HTTP modules emits lots of events in the Asp.Net request pipeline where we can write our own logic so it is termed as event based methodology. Each and every request passes through HTTP modules.

HTTP handlers on the other hand won’t get executed for every request, it depends on the extension of resource we are requesting so it is termed as extension based methodology. Let’s say end user make a request to image with .jpg extension but we internally retrieves the image from database and send it as a response. HTTP handler fits here best. 

Support for Multiple Files Upload

Since HTML 5 provides support for multiple files upload from browsers, ASP.NET 4.5 has provided new methods and properties to support multiple files upload. Following are the new properties of FileUpload control that support multiple files upload.

  • AllowMultiple: Specifies that FileUpload control should allow uploading multiple files. Of course this is possible only when Browser supports that feature.
  • HasFiles: Returns true if any files have been uploaded.
  • PostedFiles: Represents all files uploaded from client.
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void btnUpload_Click(object sender, EventArgs e)
    {
      // Check whether FileUpload has any files 
      if (FileUpload1.HasFiles)
      {
       // Iterate over files
       foreach (HttpPostedFile file in FileUpload1.PostedFiles)
       {           
file.SaveAs(Server.MapPath("~/files/") + file.FileName);
       }
       lblMsg.Text = "Uploaded " +  FileUpload1.PostedFiles.Count + " files!";
      }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server">
Select Files to upload :
 <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true"/>
<p />
 <asp:Button ID="btnUpload" runat="server" Text="Upload"  
    OnClick="btnUpload_Click" />
<p />
 <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</form>
</body>
</html>

Strongly Typed Data Binding

In previous version of ASP.NET data binding expressions were not strongly typed. All that we had was eval() and bind() functions to bind data to controls.

But whether the expression given with eval() and bind() is valid or not is not known until runtime. So these expressions do not support IntelliSense for member names, and compile-time checking.

ASP.NET 4.5 introduced a new property called ItemType for data bind controls like DataList.  ItemType specifies the type of data that is being bound to control.

Inside the scope of data-binding expression, two new variables – Item and BindItem – are made available. These variables are strongly typed and support intellisense, compile-time checking etc.

The following example shows how to use strongly typed binding.
Create a class that is used in data binding.

public class Employee
{
    public int Id { get;set;}
    public string Name { get;set;}
    public string JobTitle { get;set;}
    public int Salary { get;set; }
}

Then create an Asp.net page with DataList and specify the type of the item that is bound to items in DataList is Employee using ItemType attribute of DataList. For simplicity sake, I created a List of Employee objects and bind the list to DataList.
Inside data-binding expressions of DataList, you can use Item variable to get access to Employee object. So, Item.Name refers to name of the employee, Item.Salary refers to salary of the employee. We get Intellisence support with Item variable.

 
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)    
{
        List<Employee> employees = new List<Employee> {
              new Employee { Id = 1,  Name = "Ronaldo", JobTitle = "Programmer", Salary = 50000},
new Employee { Id = 2,  Name = "Alanso", JobTitle = "Tester", Salary = 30000},
new Employee { Id = 3,  Name = "Ramos", JobTitle = "DBA", Salary = 70000}
  };
	  dataListEmployees.DataSource = employees;
dataListEmployees.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <h2>List Of Employees</h2>
        <asp:DataList ID="dataListEmployees" runat="server"
            ItemType="Employee">
            <ItemTemplate>
                <b><%# Item.Id %> </b>
                <br />
                <%# Item.Name%>
                <br />
                <%# Item.JobTitle %>
                <br />
                <%# Item.Salary %>
                <p />
            </ItemTemplate>
        </asp:DataList>
    </form>
</body>
</html>

Html Encoding in Data Binding Expression

You can now HTML-encode the result of data-binding expressions. Add a colon (:) to the end of the <%# prefix that marks the data-binding expression.

<asp:TemplateField HeaderText="Address">
        <ItemTemplate><%#: Item.Address %></ItemTemplate>
</asp:TemplateField>

Model Binding

Model binding extends data binding in ASP.NET Web Forms controls to work with code-focused data access.
To configure a data control to use model binding to select data, you set the control's SelectMethod property to the name of a method in the page's code. So the data comes from a method within the page.

The data control calls the method at the appropriate time in the page life cycle and automatically binds the returned data. There's no need to explicitly call the DataBind method.

The following example shows how to bind data to GridView using a method in the page. I am using Employee class from previous example.

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
      
    public List<Employee> GetEmployees()
    {
        List<Employee> employees = new List<Employee> {
              new Employee { Id = 1,  Name = "Ronaldo", JobTitle = "Programmer", Salary = 50000},
new Employee { Id = 2,  Name = "Alanso", JobTitle = "Tester", Salary = 30000},
new Employee { Id = 3,  Name = "Ramos", JobTitle = "DBA", Salary = 70000}
        };
return employees;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <h2>List Of Employees</h2>
        <asp:GridView ID="gvEmployees" runat="server" SelectMethod="GetEmployees">
        </asp:GridView>
    </form>
</body>
</html>

Filtering Data

To filter the returned data, parameters have to be added to the select method. These parameters will be populated by the model binding at run time.

From where the value for parameter is taken can be specified using Value Providers, which are attributes.
The following table lists attributes related to different value providers.

  • ControlAttribute - Controls on the page
  • QueryStringAttribute - Query string values
  • ViewStateAttribute - View State
  • SessionAttribute - Session state
  • CookieAttribute - Cookies
  • FormAttribute - Posted form data

The following example displays details of employees whose salaries are more than the given value. It uses ControlAttribute to copy value entered in textbox to parameter and uses it to filter data.

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    public List<Employee> GetEmployees()
    {
        List<Employee> employees = new List<Employee> {
              new Employee { Id = 1,  Name = "Ronaldo", JobTitle = "Programmer", Salary = 50000},
new Employee { Id = 2,  Name = "Alanso", JobTitle = "Tester", Salary = 30000},
              new Employee { Id = 3,  Name = "Ramos", JobTitle = "DBA", Salary = 70000}
};
return employees;
}
 public List<Employee> GetSelectedEmployees( [System.Web.ModelBinding.Control ("txtSalary")] string salary )
{
  if (Page.IsPostBack)
        {
            var employees = GetEmployees();
            return employees.FindAll(e => e.Salary >  Int32.Parse(salary));
        }
        else
            return null; 
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
      
        <h2>List Of Employees</h2>
        Minmum Salary : <asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
        <p />

        <asp:GridView ID="gvEmployees" runat="server" SelectMethod="GetSelectedEmployees">
  </asp:GridView>
    </form>
</body>
</html>

New ASP.NET Request Validation Features

By default, ASP.NET performs request validation — it examines requests to look for markup or script in fields, headers, cookies, and so on. If any is detected, ASP.NET throws an exception. This acts as a first line of defense against potential cross-site scripting attacks.

ASP.NET 4.5 makes it easy to selectively read unvalidated request data. ASP.NET 4.5 also integrates the popular AntiXSS library, which was formerly an external library.

Developers have frequently asked for the ability to selectively turn off request validation for their applications. For example, if your application is forum software, you might want to allow users to submit HTML-formatted forum posts and comments, but still make sure that request validation is checking everything else.

ASP.NET 4.5 introduces two features that make it easy for you to selectively work with unvalidated input: deferred ("lazy") request validation and access to unvalidated request data.

Deferred ("lazy") request validation

In ASP.NET 4.5, by default all request data is subject to request validation. However, you can configure the application to defer request validation until you actually access request data. (This is sometimes referred to as lazy request validation, based on terms like lazy loading for certain data scenarios.) You can configure the application to use deferred validation in the Web.config file by setting the requestValidationMode attribute to 4.5 in the httpRUntime element, as in the following example:

<httpRuntime requestValidationMode="4.5" ... />

When request validation mode is set to 4.5, request validation is triggered only for a specific request value and only when your code accesses that value. For example, if your code gets the value of Request.Form["forum_post"], request validation is invoked only for that element in the form collection. None of the other elements in the Form collection are validated. In previous versions of ASP.NET, request validation was triggered for the entire request collection when any element in the collection was accessed. The new behavior makes it easier for different application components to look at different pieces of request data without triggering request validation on other pieces.

Support for unvalidated requests

Deferred request validation alone doesn't solve the problem of selectively bypassing request validation. The call to Request.Form["forum_post"] still triggers request validation for that specific request value. However, you might want to access this field without triggering validation because you want to allow markup in that field.

To allow this, ASP.NET 4.5 now supports unvalidated access to request data. ASP.NET 4.5 includes a new Unvalidated collection property in the HttpRequest class. This collection provides access to all of the common values of request data, like Form, QueryString, Cookies, and Url.
Using the forum example, to be able to read unvalidated request data, you first need to configure the application to use the new request validation mode:

<httpRuntime requestValidationMode="4.5" ...
/>

You can then use the HttpRequest.Unvalidated property to read the unvalidated form value:

var s = context.Request.Unvalidated.Form["forum_post"];

Security Note: Use unvalidated request data with care! ASP.NET 4.5 added the unvalidated request properties and collections to make it easier for you to access very specific unvalidated request data. However, you must still perform custom validation on the raw request data to ensure that dangerous text is not rendered to users.

AntiXSS Library

Due to the popularity of the Microsoft AntiXSS Library, ASP.NET 4.5 now incorporates core encoding routines from version 4.0 of that library.

The encoding routines are implemented by the AntiXssEncoder type in the new System.Web.Security.AntiXss namespace. You can use the AntiXssEncoder type directly by calling any of the static encoding methods that are implemented in the type. However, the easiest approach for using the new anti-XSS routines is to configure an ASP.NET application to use the AntiXssEncoder class by default. To do this, add the following attribute to the Web.config file:

<httpRuntime ...
  encoderType="System.Web.Security.AntiXss.AntiXssEncoder,System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /

When the encoderType attribute is set to use the AntiXssEncoder type, all output encoding in ASP.NET automatically uses the new encoding routines.
These are the portions of the external AntiXSS library that have been incorporated into ASP.NET 4.5:

  • HtmlEncode, HtmlFormUrlEncode, and HtmlAttributeEncode
  • XmlAttributeEncode and XmlEncode
  • UrlEncode and UrlPathEncode (new)
  • CssEncode

Support for WebSockets Protocol

WebSockets protocol is a standards-based network protocol that defines how to establish secure, real-time bidirectional communications between a client and a server over HTTP. Microsoft has worked with both the IETF and W3C standards bodies to help define the protocol. The WebSockets protocol is supported by any client (not just browsers), with Microsoft investing substantial resources supporting WebSockets protocol on both client and mobile operating systems.

WebSockets protocol makes it much easier to create long-running data transfers between a client and a server. For example, writing a chat application is much easier because you can establish a true long-running connection between a client and a server. You do not have to resort to workarounds like periodic polling or HTTP long-polling to simulate the behavior of a socket.

ASP.NET 4.5 and IIS 8 include low-level WebSockets support, enabling ASP.NET developers to use managed APIs for asynchronously reading and writing both string and binary data on a WebSockets object. For ASP.NET 4.5, there is a new System.Web.WebSockets namespace that contains types for working with WebSockets protocol.
A browser client establishes a WebSockets connection by creating a DOM WebSocket object that points to a URL in an ASP.NET application, as in the following example:

socket = new WebSocket("ws://contoso.com/MyWebSocketApplication.ashx");

You can create WebSockets endpoints in ASP.NET using any kind of module or handler. In the previous example, an .ashx file was used, because .ashx files are a quick way to create a handler.
According to the WebSockets protocol, an ASP.NET application accepts a client's WebSockets request by indicating that the request should be upgraded from an HTTP GET request to a WebSockets request. Here's an example:

HttpContext.Current.AcceptWebSocketRequest(// WebSocket delegate goes here)

The AcceptWebSocketRequest method accepts a function delegate because ASP.NET unwinds the current HTTP request and then transfers control to the function delegate. Conceptually this approach is similar to how you use System.Threading.Thread, where you define a thread-start delegate in which background work is performed.
After ASP.NET and the client have successfully completed a WebSockets handshake, ASP.NET calls your delegate and the WebSockets application starts running. The following code example shows a simple echo application that uses the built-in WebSockets support in ASP.NET:

public async Task MyWebSocket(AspNetWebSocketContext context) 
{
        WebSocket socket = context.WebSocket; 
        while (true)
        {
          ArraySegment<byte> buffer = new ArraySegment<byte>(new byte[1024]);
           // Asynchronously wait for a message to arrive from a client 
           WebSocketReceiveResult result = 
                  await socket.ReceiveAsync(buffer, CancellationToken.None);
           // If the socket is still open, echo the message back to the client 
           if (socket.State == WebSocketState.Open) 
          {
                 string userMessage = Encoding.UTF8.GetString(buffer.Array, 0,
                         result.Count);
                  userMessage = "You sent: " + userMessage + " at " +
                          DateTime.Now.ToLongTimeString();
                  buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(userMessage));  
                  // Asynchronously send a message to the client 
                  await socket.SendAsync(buffer, WebSocketMessageType.Text, 
                         true, CancellationToken.None);
          }
           else { break; } 
        }
}

The support in .NET 4.5 for the await keyword and asynchronous task-based operations is a natural fit for writing WebSockets applications. The code example shows that a WebSockets request runs completely asynchronously inside ASP.NET. The application waits asynchronously for a message to be sent from a client by calling await socket.ReceiveAsync. Similarly, you can send an asynchronous message to a client by calling await socket.SendAsync.

In the browser, an application receives WebSockets messages through an onmessage function. To send a message from a browser, you call the send method of the WebSocket DOM type, as shown in this example:

// Receive a string message from the server. 
 socket.onmessage = function(msg) 
{
        document.getElementById("serverData").innerHTML = msg.data;
};
// Send a string message from the browser. 
socket.send(document.getElementById("msgText"));

In the future, we might release updates to this functionality that abstract away some of the low-level coding that is required in this release for WebSockets applications.

Bundling and Minification

Bundling lets you combine individual JavaScript and CSS files into a bundle that can be treated like a single file. Minification condenses JavaScript and CSS files by removing whitespace and other characters that are not required. These features work with Web Forms, ASP.NET MVC, and Web Pages.

Bundles are created using the Bundle class or one of its child classes, ScriptBundle and StyleBundle. After configuring an instance of a bundle, the bundle is made available to incoming requests by simply adding it to a global BundleCollection instance. In the default templates, bundle configuration is performed in a BundleConfig file. This default configuration creates bundles for all of the core scripts and css files used by the templates.

Bundles are referenced from within views by using one of a couple possible helper methods. In order to support rendering different markup for a bundle when in debug vs. release mode, the ScriptBundle and StyleBundle classes have the helper method, Render. When in debug mode, Render will generate markup for each resource in the bundle. When in release mode, Render will generate a single markup element for the entire bundle. Toggling between debug and release mode can be accomplished by modifying the debug attribute of the compilation element in web.config as shown below:

<system.web> 
<compilation targetframework="4.5" debug="true" />
...</system.web>

Additionally, enabling or disabling optimization can be set directly via the BundleTable.EnableOptimizations property.

BundleTable.EnableOptimizations = true;

When files are bundled, they are first sorted alphabetically (the way they are displayed in Solution Explorer). They are then organized so that known libraries and their custom extensions (such as jQuery, MooTools, and Dojo) are loaded first. For example, the final order for the bundling of the Scripts folder as shown above will be:

  1. jquery-1.6.2.js
  2. jquery-ui.js
  3. jquery.tools.js
  4. a.js

CSS files are also sorted alphabetically and then reorganized so that reset.css and normalize.css come before any other file. The final sorting of the bundling of the Styles folder shown above will be this:

  1. reset.css
  2. content.css
  3. forms.css
  4. globals.css
  5. menu.css
  6. styles.css

Performance Improvements for Web Hosting

The .NET Framework 4.5 and Windows 8 introduce features that can help you achieve a significant performance boost for web-server workloads. This includes a reduction (up to 35%) in both startup time and in the memory footprint of web hosting sites that use ASP.NET.

Key performance factors

Ideally, all websites should be active and in memory to assure quick response to the next request, whenever it comes. Factors that can affect site responsiveness include:

  • The time it takes for a site to restart after an app pool recycles. This is the time it takes to launch a web server process for the site when the site assemblies are no longer in memory. (The platform assemblies are still in memory, since they are used by other sites.) This situation is referred to as "cold site, warm framework startup" or just "cold site startup."
  • How much memory the site occupies. Terms for this are "per-site memory consumption" or "unshared working set."

The new performance improvements focus on both of these factors.

Requirements for New Performance Features

The requirements for the new features can be broken down into these categories:

  • Improvements that run on the .NET Framework 4.
  • Improvements that require the .NET Framework 4.5 but can run on any version of Windows.
  • Improvements that are available only with .NET Framework 4.5 running on Windows 8.

Performance increases with each level of improvement that you are able to enable.
Some of the .NET Framework 4.5 improvements take advantage of broader performance features that apply to other scenarios as well.

Tuning garbage collection to optimize for memory

Requirement: .NET Framework 4.5
Once a site is running, its use of the garbage-collector (GC) heap can be a significant factor in its memory consumption. Like any garbage collector, the .NET Framework GC makes tradeoffs between CPU time (frequency and significance of collections) and memory consumption (extra space that is used for new, freed, or free-able objects).

For the .NET Framework 4.5, instead of multiple standalone settings, a workload-defined configuration setting is available that enables all of the previously recommended GC settings as well as new tuning that delivers additional performance for the per-site working set.

To enable GC memory tuning, add the following setting to the Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config file:

<configuration> 
  <!-- ... -->
  <runtime>
        <performanceScenario value="HighDensityWebHosting"  />
  <!-- ... --> 

(If you're familiar with the previous guidance for changes to aspnet.config, note that this setting replaces the old settings — for example, there is no need to set gcServer, gcConcurrent, etc. You do not have to remove the old settings.)

Prefetching for web applications

Requirement: .NET Framework 4.5 running on Windows 8
For several releases, Windows has included a technology known as the prefetcher that reduces the disk-read cost of application startup. Because cold startup is a problem predominantly for client applications, this technology has not been included in Windows Server, which includes only components that are essential to a server. Prefetching is now available in the latest version of Windows Server, where it can optimize the launch of individual websites.

For Windows Server, the prefetcher is not enabled by default. To enable and configure the prefetcher for high-density web hosting, run the following set of commands at the command line:

sc config sysmain start=auto 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" /v EnablePrefetcher /t REG_DWORD /d 2 /f
reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Prefetcher" /v MaxPrefetchFiles /t REG_DWORD /d 8192 /f
net start sysmain

Then, to integrate the prefetcher with ASP.NET applications, add the following to the Web.config file:

<configuration> 
  <!-- ... -->
  <system.web>
        <compilation enablePrefetchOptimization="true" />
  <!-- ... --> 

Strongly Typed Data Controls

In ASP.NET 4.5, Web Forms includes some improvements for working with data. The first improvement is strongly typed data controls. For Web Forms controls in previous versions of ASP.NET, you display a data-bound value using Eval and a data-binding expression:

<ul> 
        <asp:Repeater runat="server" ID="customers">
          <ItemTemplate>
                 <li>
                         First Name: <%# Eval("FirstName")%><br />
                         Last Name: <%# Eval("LastName")%><br />
                 </li>
          </ItemTemplate>
        </asp:Repeater>
</ul>

For two-way data binding, you use Bind:

<asp:FormView runat="server" ID="editCustomer"> 
        <EditItemTemplate>
          <div>
                 <asp:Label runat="server" AssociatedControlID="firstName">
                         First Name:</asp:Label>
                  <asp:TextBox ID="firstName" runat="server"
                         Text='<%#Bind("FirstName") %>' />
          </div>
          <div>
                  <asp:Label runat="server" AssociatedControlID="lastName"> 
                         First Name:</asp:Label>
                 <asp:TextBox ID="lastName" runat="server"
                         Text='<%# Bind("LastName") %>' />
          </div>
          <asp:Button runat="server" CommandName="Update"/>
        </EditItemTemplate>
</asp:FormView>

At run time, these calls use reflection to read the value of the specified member and then display the result in the markup. This approach makes it easy to data bind against arbitrary, unshaped data.

However, data-binding expressions like this don't support features like IntelliSense for member names, navigation (like Go To Definition), or compile-time checking for these names.

To address this issue, ASP.NET 4.5 adds the ability to declare the data type of the data that a control is bound to. You do this using the new ItemType property. When you set this property, two new typed variables are available in the scope of data-binding expressions: Item and BindItem. Because the variables are strongly typed, you get the full benefits of the Visual Studio development experience.

For two-way data-binding expressions, use the BindItem variable:

<asp:FormView runat="server" ID="editCustomer"> 
        <EditItemTemplate>
          <div>
                 <asp:Label runat="server" AssociatedControlID="firstName">
                         First Name:</asp:Label>
                 <asp:TextBox ID="firstName" runat="server" 
                          Text='<%#BindItem.FirstName %>' />
          </div>
          <div>
                  <asp:Label runat="server" AssociatedControlID="lastName"> 
                         First Name:</asp:Label>
                  <asp:TextBox ID="lastName" runat="server" 
                          Text='<%#BindItem.LastName %>' />
          </div>
           <asp:Button runat="server" CommandName="Update"/> 
        </EditItemTemplate>
</asp:FormView>

Most controls in the ASP.NET Web Forms framework that support data binding have been updated to support the ItemType property.

HTML5 Updates

Some improvements have been made to Web Forms server controls to take advantage of new features of HTML5:

  • The TextMode property of the TextBox control has been updated to support the new HTML5 input types like email, datetime, and so on.
  • The FileUpload control now supports multiple file uploads from browsers that support this HTML5 feature.
  • Validator controls now support validating HTML5 input elements.
  • New HTML5 elements that have attributes that represent a URL now support runat="server". As a result, you can use ASP.NET conventions in URL paths, like the ~ operator to represent the application root (for example, <video runat="server" src="~/myVideo.wmv" />).
  • The UpdatePanel control has been fixed to support posting HTML5 input fields.

ASP.NET MVC 4

ASP.NET MVC 4 Beta is now included with Visual Studio 11 Beta. ASP.NET MVC is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern. ASP.NET MVC 4 makes it easy to build applications for the mobile Web and includes ASP.NET Web API, which helps you build HTTP services that can reach any device.

ASP.NET Web Pages 2

New features include the following:

  • New and updated site templates.
  • Adding server-side and client-side validation using the Validation helper.
  • The ability to register scripts using an assets manager.
  • Enabling logins from Facebook and other sites using OAuth and OpenID.
  • Adding maps using the Maps helper.
  • Running Web Pages applications side-by-side.
  • Rendering pages for mobile devices.

Configuration Changes in ASP.NET 4.5 Website Templates

The following changes have been made to the default Web.config file for site that are created using website templates in Visual Studio 2012 Release Candidate:

  • In the <httpRuntime> element, the encoderType attribute is now set by default to use the AntiXSS types that were added to ASP.NET.
  • Also in the <httpRuntime> element, the requestValidationMode attribute is set to "4.5". This means that by default, request validation is configured to use deferred ("lazy") validation.
  • The <modules> element of the <system.webServer> section does not contain a runAllManagedModulesForAllRequests attribute. (Its default value is false.) This means that if you are using a version of IIS 7 that has not been updated to SP1, you might have issues with routing in a new site.

Page Inspector

Page Inspector is a tool that renders a web page (HTML, Web Forms, ASP.NET MVC, or Web Pages) in the Visual Studio IDE and lets you examine both the source code and the resulting output. For ASP.NET pages, Page Inspector lets you determine which server-side code has produced the HTML markup that is rendered to the browser.

Summary
Microsoft's ASP.NET is a language and platform-neutral and interoperable technology. It is one of the most successful web technologies till date. It has matured over the years with the latest version, ASP.NET 4.5, having a number of new features and enhancements.

This cover article was a quick glance at the new features of ASP.NET 4.5.








}