gpt4 book ai didi

asp.net-mvc - 当我调试 ASP.NET MVC 应用程序时,为什么 Application_Start() 事件不触发?

转载 作者:行者123 更新时间:2023-12-03 05:28:16 25 4
gpt4 key购买 nike

目前,我的 Global.asax.cs 文件中有以下例程:

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

当我点击F5时,应用程序会启动,除非我在~/Views/Home/中有一个名为Index.aspx的 View > 文件夹时,我收到“查看缺失”错误消息,尽管我已经重新定义了默认路由并删除了 HomeController。我希望获得路由调试器,如果没有,至少需要请求 ~/Views/Arrangement/Index.aspx
调试时永远不会命中 RegisterRoutes(Routetable.Routes); 上的断点。

我尝试过构建、重建、重新启动 VS、清理、再次重建等,但似乎没有任何效果。为什么应用程序不运行当前版本的代码?

最佳答案

我找到了以下答案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.

这就是我的案例中发生的情况。

关于asp.net-mvc - 当我调试 ASP.NET MVC 应用程序时,为什么 Application_Start() 事件不触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/967813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com