4

I need to upgrade a MVC 4 project developed in VS 2012 (.NET Framework 4.5) to MVC 5 (.NET Framework 4.5.1).

First Scenario

I've followed the the tutorial on asp.net ( http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 ).The project builds successfully but when I run it I got an error: 403.14 - The Web server is configured to not list the contents of this directory. The directory browsing is disabled (correct). This should map to /home/index? I have confirmed that the DNS/binding is working by putting a static html file in the site and this works fine.

Second Scenario

I created an empty project in VS2013 and did copy/include all files. It builds successfully and runs on local machine fine but when I publish it to the server I got an error: 403 - Forbidden: Access is denied. I have also confirmed that the DNS/binding is working by putting a static html file in the site.

I have also tried to publish the app’s ‘old version’ (MVC 4) to the server and it works fine.

IDE: VS 2013 .NET Framework: 4.5.1 Local OS: Win 7 SP1 Server: Win Server 2012 Standard

RMD
  • 2,907
  • 30
  • 47
user2178726
  • 95
  • 1
  • 3
  • 8

2 Answers2

12

First of all you need to update all the existing nuget packages.Because some are incompatible with the new one. Before doing it please keep a back up of your existing application

Step 1 : Change the framework to 4.5.1. You need to change the target framework to atleast 4.5 by right clicking the projects.

enter image description here Step2 : Then you need to update the packages at the solution level.Because it will get the ability to update the packages in all the projects in the solution.For this right click the solution and select 'Manage Nuget Packages for solution' option.

enter image description here

Step3 : From the install packages select the Microsoft.AspNet.Web.Helpers.Mvc packages and Uninstall it.Because it is renamed in the new version ,MVC5.For uninstalling click the Manage button and uncheck the webproject and click ok.

enter image description here

Step4 : Then go to the update packages and update some packages such as Microsoft.ASP.NET MVC,Entity Framework and WebApi version 2. My strategy is to updating to the top level packages.When updating this it will update some ather packages.Now you can see the changes in packages.config file such as MVC4 to MVC5,Razor version change from 2 to 3 and also Webpage version from 2 to 3.

enter image description here

Step5 : Change the version in our config file as well like below.

enter image description here

enter image description here

these are the changes in the top level config file

Step 6 : Then also you need to done some changes in views config file such as updating the razor version to 3 and MVC version to 5 in all the parts of the config file

enter image description here

Step 7 : install one more package. Go to manage nuget manager option >> select online table >> search for Microsoft.Aspnet.Webhelpers and install the package.

enter image description here

**Step 8 : ** Unload the webproject and right click and select edit proj option and the remove the guid starting with E3 because we no need this guid in our new project.

enter image description here

Save and reload the project again and build and run the application Hope this informations helps you

Jameel Moideen
  • 7,542
  • 12
  • 51
  • 79
4

I came across this issue when upgrading an MVC 4 project to MVC 5.

The culprit in my case was that the default route was {controller}/{action}/{id} but the default values did not specify that the id route token was optional (i.e. UrlParameter.Optional). Now, Instead of suggesting that a matching route could not be found, IIS ends up falling through to the Static File Handler that then assumes that you are trying to browse a directory on the web server as there is no extension in the URL, hence the 403 Forbidden error.

So, to fix this, ensure that your default route provides defaults for all the route tokens; in my case, this looked like so

routes.MapRoute(
    null, 
    "{controller}/{action}/{id}", 
    new { controller = "Home", action="Index" id = UrlParameter.Optional });
Russ Cam
  • 124,184
  • 33
  • 204
  • 266