Sunday 7 July 2013

New and Improved Features in Visual Studio 2012 and ASP.NET

 New and Improved Features in Visual Studio 2012 and ASP.NET
Recently, Microsoft released the Visual Studio 2012.2 ASP.NET and Web Tools Refresh and the Visual Studio Update #2. In this article, I will highlight a few of the new and improved features that you will want to consider using right away. Before you can take advantage of these features, you will need to download and install these updates:
There are some exceptions to this requirement as some of these updates are available separately as NuGet Packages. Those situations will be called out when applicable.
The following are a few of the new and improved features in Visual Studio 2012 and ASP.NET:
  • Paste JSON As Classes
  • ASP.NET-friendly URLS
  • Improved Emmet Coding Support
  • Web API Help
  • Page Inspector
Paste JSON As Classes
Just about every modern Web application works with JSON and needs to de-serialize JSON to concrete classes. For simple JSON, creating classes is not difficult. For complex JSON, such as the following (compliments of json.org), manual class creation is complex and tedious.
"
Just about every modern Web application works with JSON and needs to de-serialize JSON to concrete classes.
"
Once the selected JSON is copied to the clipboard, within Visual Studio in the code editor, you can right-click the mouse, select Paste Special, Paste JSON As Classes. Figure 1 illustrates the context menu option and Figure 2 illustrates the classes created from the paste operation. The Paste JSON As Classes feature will save you hours of work!
Click for a larger version of this image.

Figure 1: When JSON is copied to the clipboard, the Paste JSON As Classes option is available.

Click for a larger version of this image.

Figure 2: The parsed JSON copied to the clipboard produced these classes.

"
The paste JSON as a class feature will save you hours of work!
"
ASP.NET-Friendly URLS
If you have worked with ASP.NET Web Forms, you know that your application’s URLs have the .aspx extension and when you saw ASP.NET MVC hit the street, with extension-less URLs, you may have looked at that feature with a bit of envy. Today, your ASP.NET Web Forms can have the same extension-less URLs. Figure 3illustrates the old-form URL with the .aspx extension.
Click for a larger version of this image.

Figure 3: This is the old-form of ASP.NET Web Form URL with the .aspx extension.

Figure 4 illustrates the new extension-less form.
Click for a larger version of this image.

Figure 4: This is the new form of ASP.NET Web Form extension-less URL.

If you are not able to install the 2012.2 updates and wish to take advantage of extension-less URLs, you can install the NuGet Package illustrated in Figure 5.
Click for a larger version of this image.

Figure 5: The ASP.NET friendly extension-less URL is available as a separate NuGet Package.

Figure 6 illustrates how the friendly URL feature is wired into the process. Figure 6 also illustrates the new friendly URL extension methods linked to the Request Object.
Click for a larger version of this image.

Figure 6: The friendly extension-less URL feature is wired up in the App_Start\RouteConfig.RegisterRoutes Method.

If you need to create a friendly URL in your mark-up, you can do so without the need for concatenation with the following code:
<%@ Import Namespace="Microsoft.AspNet.FriendlyUrls" %>
After the namespace has been imported to the page, you create a link:
<%=FriendlyUrl.Href("~/mylink","param1", 1) %>
The result is: /mylink/param1/1. You can pass any number of parameters necessary to create your link.

No comments:

Post a Comment