为什么调试我的ASP.NET MVC应用程序时Application_Start()事件不会触发? [英] Why does not the Application_Start() event fire when I debug my ASP.NET MVC app?
问题描述
我目前在我的 Global.asax.cs
文件中有以下例程:
code> 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);
//用Phil Haacks路由调试器调试路由(下面的链接)
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
路由调试器 ...
当我点击 F5
,应用程序启动,除非我在〜/ Views中有一个名为
文件夹,我得到查看缺失错误消息,虽然我已重新定义默认路由并删除 Index.aspx
的视图/ Home / HomeController
。我希望得到路由调试器,如果不是至少一个请求〜/ Views / Arrangement / Index.aspx
。
断点> RegisterRoutes(Routetable.Routes);
我尝试了构建,重建,重新启动VS,清洗,重建等,但没有什么似乎工作。为什么应用程序不运行当前版本的代码?
我发现了问题:
这个MVC应用程序是一个更大的解决方案的一部分,其中我有一个点设置另一个项目为一个x86环境(我运行x64)。当我这样做,显然所有其他项目 - 即使是后来添加的 - 被设置不建立在 Ctrl + Shift + B
,我想这就是为什么调试器没有
解决方案:
进入解决方案构建属性(右键单击解决方案,选择属性,然后选择左侧菜单中的Build),并在列表中项目名称旁边的Build复选框中选中。
I currently have the following routines in my Global.asax.cs
file:
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);
}
When I hit F5
, the application fires up and unless I have a view named Index.aspx
in the ~/Views/Home/
folder, I get the "View missing" error message, although I have re-defined the default route and removed the HomeController
. I would expect to get the routing debugger, and if not that at least a request for ~/Views/Arrangement/Index.aspx
.
A breakpoint on RegisterRoutes(Routetable.Routes);
is never hit when debugging.
I have tried building, rebuilding, restarting VS, cleaning, rebuilding again etc, but nothing seems to work. Why doesn't the application run the current version of the code?
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.
这篇关于为什么调试我的ASP.NET MVC应用程序时Application_Start()事件不会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!