Search This Blog


Wednesday, July 30, 2008

"The Resource Cannot be Found" When Upgrade to ASP.Net MVC Preview 3

You have an MVC application built using preview 2. Now you want to upgrade to Preview 3 or later. You make all the reference changes, and you recompile your application. Viola! No compilation error. Then you run all your tests, all of them pass!

You think that your application is safe from regression. But wait, if you press F5 and try to run the application, you will get this yellow screen of death:
It's a stark reminder than even though unit tests pass, but the application is far from done.
How are you going to fix this problem?

Well, you won't encounter this if you read a 8 page ASP.NET MVC readme before you do your upgrade. But I know you are just like me, who is not going to read any readme, especially if the readme needs third party software to open, such as Microsoft Word. You only scramble for solutions when you encounter puzzling errors, and which is why you are here, right?
Now, the solution on how to solve this problem is contained in that readme file. Or, if you don't want to read a Microsoft Word document, let me just copy and paste the relevant portion and hope that it helps you:

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=
Bon Voyage!


Fahima said...

your site is very nice ...
this is very helpful and attractive.
visit for help help

Ranjith said...

Thanks it helped me to configure my site otherway round