I have been stuck on this issue for several hours now.
我在这个问题上已经纠缠了好几个小时了。
I have a controller called 'DecisionPoint' and I have a breakpoint set on it's 'ApplicationState' action. No matter what I try I keep getting a 404 in the browser. I suspected that my route was not correct so I downloaded a route debugger and it turns our the URLs I am trying match the Controller and the action. So why do I get a 404 and never see the breakpoint hit?
我有一个名为“DecisionPoint”的控制器,我在它的“ApplicationState”动作上有一个断点集。不管我怎么做,我在浏览器里总是得到404页面。我怀疑我的路径不正确,所以我下载了一个路径调试器,它将我正在尝试的url与控制器和操作匹配。那么,为什么我得到404,却没有看到断点呢?
/DecisionPoint/ApplicationState/no/worky --> 404
/ DecisionPoint ApplicationState /不/成功- - > 404
Controller:
控制器:
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");
Route
路线
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**
I create a whole new controller and it works. This is now what my route table looks like. The state controller correclty routes to SaveState
我创建了一个全新的控制器。这就是我的路由表。州控制程序相关地路由到SaveState
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);
}
}
So I am stumped..
所以我难住了. .
7 个解决方案
#1
12
Make sure your controller class is called DecisionPointController and not DecisionPoint
确保您的控制器类被称为DecisionPointController,而不是DecisionPoint
#2
10
If your AreaRegistration
class and Controller
class are not in the same namespace, you'll be in this situation - the route will match (and RouteDebugger will confirm this) but you'll get a 404 at the "correct" url.
如果AreaRegistration类和Controller类不在同一个名称空间中,那么您将处于这种情况——路由将匹配(RouteDebugger将对此进行确认),但您将在“正确”url上获得404。
The solution is to make sure both clases are in the same namespace.
解决方案是确保两个clases都位于同一个名称空间中。
#3
2
You can use RouteDebugger to check your route.
您可以使用RouteDebugger检查路由。
http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/
http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/
It was very useful for me.
这对我很有用。
#4
2
This can happen due to your Controller
being in another project which references a different version of System.Web.Mvc
!
这可能是由于您的控制器在另一个项目中,它引用了不同版本的System.Web.Mvc!
I had the same symptoms - the correct route was found, but got a 404! On HttpHandler.ProcessRequest, an exception was thrown saying the handler's controller does not implement IController
.
我也有同样的症状——找到了正确的路线,但是得到了404!HttpHandler。ProcessRequest,一个异常被抛出,说处理器的控制器没有实现IController。
#5
2
I just recently ran into this same problem. For me the problem was that I had two controllers with the same name if different namespaces (One was in an area).
我最近遇到了同样的问题。对我来说,问题是如果名称空间不同(一个在某个区域),我有两个名称相同的控制器。
#6
0
I'm no routes guru, but I have always added all parameters for the default argument:
我不是路由专家,但我总是为默认参数添加所有参数:
routes.MapRoute(
"DecisionPointState", // Route name
"DecisionPoint/ApplicationState/{fileName}/{stateString}", // URL with parameters
new {controller = "DecisionPoint",
action = "ApplicationState"
fileName = UrlParameter.Optional,
stateString = UrlParameter.Optional
} // Parameter defaults
);
#7
0
In my case, the answer for the same problem was a matter of needing to "include in project" the relevant controllers and views instead of incorrect routing rules.
在我的例子中,相同问题的答案是需要“在项目中包含”相关的控制器和视图,而不是不正确的路由规则。
When mine were created, they weren't automatically included for some reason. This problem was revealed after I closed and re-opened the solution.
当我的代码被创建时,由于某些原因,它们不会自动包含在其中。这个问题在我关闭并重新打开解决方案后暴露出来。
{+1 hate} awarded to Visual Studio for its faulty hyper-automation sending me digging through Web.Config files, trying to tack on extensions, and even trying (and failing) to whip up a decent ErrorController.
{+1仇恨}授予Visual Studio,因为它错误的超自动化让我通过网络进行挖掘。配置文件,尝试添加扩展,甚至尝试(并且失败)生成一个像样的ErrorController。
#1
12
Make sure your controller class is called DecisionPointController and not DecisionPoint
确保您的控制器类被称为DecisionPointController,而不是DecisionPoint
#2
10
If your AreaRegistration
class and Controller
class are not in the same namespace, you'll be in this situation - the route will match (and RouteDebugger will confirm this) but you'll get a 404 at the "correct" url.
如果AreaRegistration类和Controller类不在同一个名称空间中,那么您将处于这种情况——路由将匹配(RouteDebugger将对此进行确认),但您将在“正确”url上获得404。
The solution is to make sure both clases are in the same namespace.
解决方案是确保两个clases都位于同一个名称空间中。
#3
2
You can use RouteDebugger to check your route.
您可以使用RouteDebugger检查路由。
http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/
http://helios.ca/2009/05/26/aspnet-mvc-route-debugging/
It was very useful for me.
这对我很有用。
#4
2
This can happen due to your Controller
being in another project which references a different version of System.Web.Mvc
!
这可能是由于您的控制器在另一个项目中,它引用了不同版本的System.Web.Mvc!
I had the same symptoms - the correct route was found, but got a 404! On HttpHandler.ProcessRequest, an exception was thrown saying the handler's controller does not implement IController
.
我也有同样的症状——找到了正确的路线,但是得到了404!HttpHandler。ProcessRequest,一个异常被抛出,说处理器的控制器没有实现IController。
#5
2
I just recently ran into this same problem. For me the problem was that I had two controllers with the same name if different namespaces (One was in an area).
我最近遇到了同样的问题。对我来说,问题是如果名称空间不同(一个在某个区域),我有两个名称相同的控制器。
#6
0
I'm no routes guru, but I have always added all parameters for the default argument:
我不是路由专家,但我总是为默认参数添加所有参数:
routes.MapRoute(
"DecisionPointState", // Route name
"DecisionPoint/ApplicationState/{fileName}/{stateString}", // URL with parameters
new {controller = "DecisionPoint",
action = "ApplicationState"
fileName = UrlParameter.Optional,
stateString = UrlParameter.Optional
} // Parameter defaults
);
#7
0
In my case, the answer for the same problem was a matter of needing to "include in project" the relevant controllers and views instead of incorrect routing rules.
在我的例子中,相同问题的答案是需要“在项目中包含”相关的控制器和视图,而不是不正确的路由规则。
When mine were created, they weren't automatically included for some reason. This problem was revealed after I closed and re-opened the solution.
当我的代码被创建时,由于某些原因,它们不会自动包含在其中。这个问题在我关闭并重新打开解决方案后暴露出来。
{+1 hate} awarded to Visual Studio for its faulty hyper-automation sending me digging through Web.Config files, trying to tack on extensions, and even trying (and failing) to whip up a decent ErrorController.
{+1仇恨}授予Visual Studio,因为它错误的超自动化让我通过网络进行挖掘。配置文件,尝试添加扩展,甚至尝试(并且失败)生成一个像样的ErrorController。