Why does not the Application_Start() event fire when I debug my ASP.NET MVC app?

后端 未结 12 1476
独厮守ぢ
独厮守ぢ 2021-01-30 16:01

I currently have the following routines in my Global.asax.cs file:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRout         


        
相关标签:
12条回答
  • 2021-01-30 16:18

    In my case the problem was between chair and keyboard - after renaming mvc project assembly, I forgot to update Global.asax to point to the correct class. So check the "Inherits" in Global.asax (in 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 your Global.asax.cs class/namespace declaration

    0 讨论(0)
  • 2021-01-30 16:20

    I've just had this problem and swapped from Local IIS to IIS Express in project properties -> web to sort it out

    0 讨论(0)
  • 2021-01-30 16:22

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

    This line should be commented out to avoid the breakpoint to happern and #ifdef debug to get sure never gets to production.

    0 讨论(0)
  • 2021-01-30 16:22

    I found the problem:

    This MVC application was part of a larger solution, in which I had at one point set another project to build for an x86 environment (I'm running x64). When I did that, apparently all other projects - even those added later - were set not to build on Ctrl+Shift+B, and I suppose that's why the debugger didn't hit my breakpoint.

    Solution:

    Go into the solution build properties (right-click Solution, select properties, and select Build on the menu on the left), and put a check in the Build checkbox next to the project name in the list.

    0 讨论(0)
  • 2021-01-30 16:26

    Below technique worked for me:
    Simple workaround is to touch global.asax after the debugger is attached in order to force an application recycle. Then during the next request, the break point that you set on Application_Start will be hit.

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

    0 讨论(0)
  • 2021-01-30 16:27

    The problem is Application_Start() triggers first then the debugger attaches.

    So the goal is to do something that would cause Application_Start() to trigger again while its still running. For debugging purposes, just run the debugger like you normally do then edit (eg add a newline) and save the web.config file.

    0 讨论(0)
提交回复
热议问题