Friday, September 16, 2011

ASP.NET MVC - Upgrading an Existing Preview2 Application to Preview 3

The information in this section describes the changes you must make to modify an ASP.NET MVC application that was created with the Preview 2 release so that it works with the Preview 3 release.

Code Changes

· Update the references to the following assemblies to point to the new Preview 3 versions of the assemblies:
  • · System.Web.Abstractions
  • · System.Web.Routing
  • · System.Web.Mvc
By default, these assemblies are located in the following folder:

%ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC Preview 3

  • For all existing action methods, change the return type from void to ActionResult.
  • Anywhere you call RenderView, change it to a call to return View. You can search for RenderView( and replace it with return View(.
  • Anywhere you call RedirectToAction, prepend the call with the return keyword. Search for RedirectToAction( and replace it with return RedirectToAction(.
  • If you use a strongly typed page, replace <%= ViewData.PropertyName %> with <%= ViewData.Model.PropertyName%>. Rather than replacing the ViewData object with your strongly typed object, the MVC framework now sets the Model property to the instance that you provide.
  • In the Global.asax file, remove the route definition for Default.aspx. In the default Preview 2 template, the route looked like the following example:
routes.Add(new Route("Default.aspx", new MvcRouteHandler())
  Defaults = new RouteValueDictionary(new { controller =  "Home", action = "Index", id = "" }),
  • In the Global.asax file, find the following default MVC route:
routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler())
Defaults = new RouteValueDictionary(new { action = "Index", id = "" }),
Replace it with the following route:
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
  • Add the following line at the very beginning of the RegisterRoutes method:
  • Edit the Default.aspx file and add the following line:
<% Response.Redirect("~/Home") %>

This redirect is not necessary for IIS 7. This is a workaround for an issue with how the Web server that is built into Visual Studio (the ASP.NET Development Server) works with routing.

Configuration Changes

  • In the Web.config file, you must change the type attribute of the httpHandler entry in the section for UrlRoutingHandler to System.Web.HttpForbiddenHandler. To do this, search for the following string in the file:
path="UrlRouting.axd" type="System.Web.Routing.UrlRoutingHandler, System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
Replace it with the following string:
path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
  • Because the version numbers of the System.Web.Abstractions and System.Web.Routing assemblies have been changed to, you must update version information in the Web.config file. In the Web.config file, search for the following string:
System.Web.Routing, Version=
Replace it with the following string:
System.Web.Routing, Version=
Search for the following string:
System.Web.Abstractions, Version=
Replace it with the following string:
System.Web.Abstractions, Version=

Sunday, July 10, 2011

June 26th Links: ASP.NET, ASP.NET MVC, .NET and NuGet


  • Introducing new ASP.NET Universal Providers: Great post from Scott Hanselman on the new System.Web.Providers we are working on. This release delivers new ASP.NET Membership, Role Management, Session, Profile providers that work with SQL Server, SQL CE and SQL Azure.

  • SassAndCoffee 0.9 Released: Paul Betts blogs about the latest release of his SassAndCoffee extension (available via NuGet). It enables you to easily use Sass and Coffeescript within your ASP.NET applications (both MVC and Webforms).


  • ASP.NET MVC Mini-Profiler: The folks at (a great site built with ASP.NET MVC) have released a nice (free) profiler they’ve built that enables you to easily profile your ASP.NET MVC 3 sites and tune them for performance.

  • Precompile your MVC Razor Views: Great post from David Ebbo that discusses a new Razor Generator tool that enables you to pre-compile your razor view templates as assemblies – which enables a bunch of cool scenarios.

  • Unit Testing Razor Views: Nice post from David Ebbo that shows how to use his new Razor Generator to enable unit testing of razor view templates with ASP.NET MVC.

  • Bin Deploying ASP.NET MVC 3: Nice post by Phil Haack that covers a cool feature added to VS 2010 SP1 that makes it really easy to \bin deploy ASP.NET MVC and Razor within your application. This enables you to easily deploy the app to servers that don’t have ASP.NET MVC 3 installed.


  • Table Splitting with EF 4.1 Code First: Great post from Morteza Manavi that discusses how to split up a single database table across multiple EF entity classes. This shows off some of the power behind EF 4.1 and is very useful when working with legacy database schemas.

  • Choosing the Right Collection Class: Nice post from James Michael Hare that talks about the different collection class options available within .NET. A nice overview for people who haven’t looked at all of the support now built into the framework.


  • NuGet 1.4 Released: Learn all about the latest release of NuGet – which includes a bunch of cool new capabilities. It takes only seconds to update to it – go for it!

  • NuGet in Depth: Nice presentation from Scott Hanselman all about NuGet and some of the investments we are making to enable a better open source ecosystem within .NET.

Original post can be found here...