Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 5 Application_Start Not Running

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?

like image 535
Filjan Avatar asked Dec 04 '14 04:12

Filjan


3 Answers

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.
like image 52
Mox Shah Avatar answered Nov 19 '22 13:11

Mox Shah


  • 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.

like image 43
Wartodust Avatar answered Nov 19 '22 11:11

Wartodust


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#" %>
like image 4
Rosdi Kasim Avatar answered Nov 19 '22 13:11

Rosdi Kasim