Why doesn't the Application_Start () event fire when I debug my ASP.NET MVC application?

In my Global.asax.cs file, I have the following routines:

 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Arrangement", action = "Index", id = "" } ); } protected void Application_Start() { RegisterRoutes(RouteTable.Routes); // Debugs the routes with Phil Haacks routing debugger (link below) RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes); } 

Routing Debugger ...

When I press F5 , the application will launch, and if I don’t have a name with the name Index.aspx in the ~/Views/Home/ folder, I get a "View Missing" error message, although I redefined the default route and deleted HomeController . I would expect to get a routing debugger, and if not the one, at least the request for ~/Views/Arrangement/Index.aspx .
Breakpoint on RegisterRoutes(Routetable.Routes); never crashes when debugging.

I tried to build, rebuild, restart VS, clean, rebuild again, etc., but nothing works. Why does the application not run the current version of the code?

+54
debugging compilation asp.net-mvc
Jun 09 '09 at 1:51
source share
12 answers

I found the problem:

This MVC application was part of a larger solution in which at some point I installed another project to build an x86 environment (I am running x64). When I did this, it is obvious that all other projects, even those that were added later, were not set to Ctrl+Shift+B , and I guess why the debugger did not hit my breakpoint.

Decision:

Go to the solution's build properties (right-click "Solution", select the properties and select "Build in the menu on the left") and select the "Build" checkbox next to the project name in the list.

+6
Jun 09 '09 at 22:56
source share

I found the following answer on forums.asp.net :

Are you using IIS7 as a server or embedded web server? I noticed when using IIS7 that if you run the debugger, release the page, then change Global.asax (the markup file, not the code) while the debugger is still working, and then refresh the page, breakpoints in Application_Start will hit.

I think what happens is that by clicking β€œplay”, VS just starts the process and then joins it, but by the time it joins it, the initial event is already running. By changing Global.asax, you force the application to reboot, and since a debugger that has already been set aside can fall into a breakpoint. Not a great solution, but it seems to work.

This is what happened in my case.

+90
Dec 02 '10 at 20:30
source share

Add System.Diagnostics.Debugger.Break(); in Application_Start() .
This will force a breakpoint.

This line should be commented out to avoid a breakpoint for happern and #ifdef debug to make sure it never goes into production.

+20
Mar 27 '12 at 1:20
source share

I believe that you need to close / stop the local debugging server so that the Application_Start() event Application_Start() again ... you have to right-click on it in the taskbar and select "Stop".

+18
Jun 09 '09 at 2:51
source share

The problem is that Application_Start() triggers fire, then the debugger attaches.

So the goal is to do something that will cause Application_Start() to start again while it is still running. For debugging purposes, just run the debugger as usual, then edit (for example, add a new line) and save the web.config file.

+7
Sep 10 '15 at 21:03
source share

In my case, I used

IIS local web server in web project settings

and I go to Use the Visual Studio Development Server , and it works.

+4
Apr 21 '14 at 15:56
source share

Below technique worked for me:
A simple workaround is to touch global.asax after the debugger is connected to force the application to restart. Then, during the next request, the breakpoint set by you on Application_Start will be deleted.

I found this here:
http://connect.microsoft.com/VisualStudio/feedback/details/634919/cannot-debug-application-start-event-in-global-asax

+4
Jul 30 '14 at 17:45
source share

In my case, the problem was between the chair and the keyboard - after renaming the assembly of the mvc project, I forgot to update Global.asax to point to the correct class. So check the "Inheritance" in Global.asax (in the visual studio, right-click on Global.asax β†’ View markup)

 <%@ Application Codebehind="Global.asax.cs" Inherits="Monster.MgsMvc.Web.MvcApplication" Language="C#" %> 

if it really matches the declaration of the global.asax.cs / namespace class

+3
Feb 06 '14 at 17:20
source share

Today I ran into the same problem and used Local IIS.

I believe this is because of the page loading. All you have to do is set a breakpoint in Application_Start. Launch the application (in my case, it went to the login screen), and then go to web.config. Edit it by adding some spaces. and then update in the browser. which will hit the breakpoint on Application_Start.

+3
Aug 22 '14 at 11:07
source share

Perhaps my solution will help someone:

  • Stop the debugger.
  • Update the RegisterRoutes code (for example, add \ remove int i = 1; ).
  • Rebuild.
  • Put a breakpoint in RegisterRoutes .
0
Jul 28 '16 at 21:39
source share

I just had this problem and changed from Local IIS to IIS Express in project properties -> web to sort it

0
Feb 22 '17 at 16:38
source share

project -> property -> web

check the "Source Code".

enter image description here

0
Jul 26 '17 at 2:30
source share



All Articles