7

I have an old MVC application that was built using Visual Studio 2010. I then upgraded to MVC 5 using Visual Studio 2013 and upgraded the NuGet packages. It builds, but when I run the application through Visual Studio it cannot find the home view. I traced it back to the the Global.asax and found out the Application_Start is never called and routes are never set then.

I have found a few questions asked here about this problem, but none of the solutions have worked for me.

Application_start not working

Application_Start not firing?

This seems so simple, but I can't find a solution to this. Any ideas?

Community
  • 1
  • 1
Filjan
  • 130
  • 1
  • 3
  • 8
  • There's a lot more to upgrading than just upgrading the packages.. there's a lot of config file changes you need to make.. have you done those? – Erik Funkenbusch Dec 04 '14 at 05:12
  • I'm new in ASP.MVC, but I met the article [how to migrate from MVC4 to MVC5](http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2) and I'd expected that migration from MVC2 will be worse – pf1957 Dec 04 '14 at 08:01

3 Answers3

7

I faced this issue few times and have tried many workarounds. what worked for me is,

  1. Start debugging your application (F5)
  2. open your global.asax file (its global.asax not global.asax.cs)
  3. change something in that file (put some whitespace or something and save it)
  4. now refresh your page in your browser.
  5. you'll see your application_start will hit breakpoints.

Solution 2

  1. Clear temp directory
  2. Restart IIS (go to command prompt and say iisreset)
  3. Start debugging of your application
  4. Then attach your application with the process.
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Mox Shah
  • 2,967
  • 2
  • 26
  • 42
  • 6
    Well after looking at my Globalasax I found the problem. My Visual Studio said I had a Global.asax and a Global.asax.cs. When I actually look at my code with Windows Explorer it turned out that I didn't have a Global.asax file and only had a Global.asax.cs file. I didn't think this was possible, but I deleted the existing file and create a new Global.asax file and everything started working. – Filjan Dec 05 '14 at 18:25
  • @Filjan Your comment was the answer for me. You should consider making it an answer outright! – DeltaTango Jul 03 '18 at 03:49
6
  • Place breakpoint within Application_Start
  • Open your Web.Config
  • Debug your application (F5)
  • Change anything in your Web.Config (adding empty line is enough)
  • Refresh your webpage
  • Application_Start will be triggered

Resetting IIS alone will not do the trick since the debugger is attached after Application_Start is triggered.

Wartodust
  • 284
  • 1
  • 6
  • 16
4

The same happened to me, Global.asax.cs is not being called at all...

As for my case, the Inherits attribute was missing in Global.asax

<%@ Application Codebehind="Global.asax.cs" Language="C#" %>

So after I changed it like so, it works!

<%@ Application Codebehind="Global.asax.cs" Inherits="MyAwesomeApp.MvcApplication" Language="C#" %>
Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154