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/no/worky --> 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
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..
The ASP.NET Routing module is responsible for mapping incoming browser requests to particular MVC controller actions. By the end of this tutorial, you will understand how the standard route table maps requests to controller actions.
Routing in ASP.NET MVC By default route is: Home controller - Index Method. routes. MapRoute has attributes like name, url and defaults like controller name, action and id (optional).
Best web development and SEO practices dictate that any webpage which does not exist, return an HTTP response code of 404, or Not Found. Basically, this response code means that the URL that you're requesting does not exist.
Dumb, but it got me:
Be sure your controller inherits from Controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With