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

后端 未结 12 1463
独厮守ぢ
独厮守ぢ 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:34

    Maybe my solution will help someone:

    1. Stop the debugger.
    2. Update the RegisterRoutes code (example - add\remove int i = 1;).
    3. Rebuild.
    4. Place a break point in RegisterRoutes.
    0 讨论(0)
  • 2021-01-30 16:37

    I hit with the same problem today and was using Local IIS.

    I believe this arises because because of the way page is loaded. All you need to do is, put a breakpoint in Application_Start. Run the application(In my case, it took to Login Screen ) and then go to web.config. Edit it - by adding some spaces. and then refresh in Browser.that will hit the breakpoint on Application_Start.

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

    project -> property -> web

    check "Native code".

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

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

    Are you using IIS7 as the server or the built-in web server? I noticed when using IIS7 that if you start the debugger, let a page come up, then change Global.asax (the markup file, not code-behind) while the debugger is still running, then refresh the page, breakpoints in Application_Start will be hit.

    I think what's happening is that pressing "play", VS just fires up the process, then attaches to it, but by the time it attaches to it the start event has already run. By changing Global.asax, you cause the app to restart and since the debugger's already attached you can hit the breakpoint. Not a great solution, but it seems to work.

    Thats's what was happening in my case.

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

    I believe you have to shutdown/stop the local debugging server in order for the Application_Start() event to fire again... you should be able to right click on it in the system tray and choose "Stop".

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

    In my case was I using

    Local IIS Web server in web project settings

    and I change to Use Visual Studio Development Server, and this works.

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