MVC 5 Application_Start not working

I have an old MVC application that was created using Visual Studio 2010. Then I was upgraded to MVC 5 using Visual Studio 2013 and updated 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 Global.asax and found that Application_Start was never called and routes were never set.

I found several questions asked here on this issue, but none of the solutions worked for me.

Application_start does not work

Application_Start not starting?

It seems so simple, but I cannot find a solution to this. Any ideas?

+5
source share
3 answers

I ran into this problem several times and tried many workarounds. what worked for me

  • Start debugging the application (F5)
  • open the global.asax file (its global.asax is not global.asax.cs)
  • change something in this file (add a space or something else and save it)
  • refresh the page in your browser.
  • You will see your application_start hit the breakpoints.

Decision 2

  • Clear temp directory
  • Restart IIS (go to command prompt and say iisreset)
  • Start debugging your application
  • Then attach your application to the process.
+5
source

Same thing with me, Global.asax.cs is not called at all ...

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

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

So, after I changed it like that, it works!

 <%@ Application Codebehind="Global.asax.cs" Inherits="MyAwesomeApp.MvcApplication" Language="C#" %> 
+4
source
  • Put a breakpoint in Application_Start
  • Open Web.Config
  • Debugging your application (F5)
  • Change something in your Web.Config (just add an empty line)
  • Refresh your web page.
  • Application_Start starts up

Resetting only IIS will not do the trick, since the debugger is connected after starting the _Start application.

+2
source

Source: https://habr.com/ru/post/1208319/


All Articles