我一直在这个问题上停留了好几个小时。为什么我在路线匹配时得到404? ASP.Net MVC
我有一个名为'DecisionPoint'的控制器,我在它的'ApplicationState'操作上设置了一个断点。无论我尝试什么,我都会在浏览器中看到404。我怀疑我的路线不正确,所以我下载了一个路由调试器,它将我所尝试的URL与我的控制器和操作相匹配。那么,为什么我会得到404并且从来没有看到断点?
/DecisionPoint/ApplicationState /没有/ worky - > 404
控制器:
public ActionResult ApplicationState(string fileName, string stateString)
{
string filePath = GetDpFilePath(fileName);
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.Load(filePath);
HtmlNode stateScriptNode =
htmlDocument.DocumentNode.SelectSingleNode("/html/head/script[@id ='applicationState']");
stateScriptNode.InnerHtml = "var applicationStateJSON =" + stateString;
htmlDocument.Save(filePath);
return Json("State Updated");
路线
routes.MapRoute(
"DecisionPointState", // Route name
"DecisionPoint/ApplicationState/{fileName}/{stateString}", // URL with parameters
new {controller = "DecisionPoint", action = "ApplicationState"} // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}`
**Update**
我创造一个全新的控制器和它的作品。这就是我的路由表的样子。状态控制器correclty路线即时存档
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"StateRoute", // Route name
"State/SaveState/{file}/{state}", // URL with parameters
new { controller = "State", action = "SaveState", file = UrlParameter.Optional, state = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"DPStateRoute", // Route name
"DecisionPoint/ApplicationState/{file}/{state}", // URL with parameters
new { controller = "DecisionPoint", action = "ApplicationState", file = UrlParameter.Optional, state = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
// RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
}
所以我难倒..
呵呵......我看不出有什么特别的错误:/ – 2011-05-16 01:39:57
你可以在该控制器中执行任何其他操作吗?在那里抛出索引动作,看看你是否击中了控制器。你有一个控制器构造函数吗?在那里放置一个断点,看看它是否触及了这一点。 – BZink 2011-05-16 03:41:46
请显示控制器代码。 – Haacked 2011-06-26 05:46:05