I am getting 404s (requested document not found) when I try to use a custom route I created per the guide here: https://kb.sitecore.net/articles/700677. My patch config is showing up in showconfig, here's what it looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<initialize>
<processor type="[obfuscated].Pipelines.Routes.RegisterCustomRoute, [obfuscated]" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
</initialize>
</pipelines>
</sitecore>
</configuration>
The processor code:
namespace BrightHorizons.Pipelines.Routes
{
public class RegisterCustomRoute
{
public virtual void Process(PipelineArgs args)
{
RouteTable.Routes.MapRoute("CustomRoute", "api/{controller}/{action}/{id}");
}
}
}
The controller action and controller name seem correct... here's what that looks like:
public class FindACenterController : GlassController
{
public ActionResult FindACenterMap()
{
...
}
}
I am trying to access it like this:
http://mysite/api/FindACenter/FindACenterMap
I also tried using a basic Default route in the RouteConfig.cs (/{controller}/{action}/{id}
) under App_Start before that and it did not work either. I am really not good at MVC routing so looking for some guidance.
UPDATE: FindACenterMap is now working, however this is not working for a different controller. Added a new route:
RouteTable.Routes.MapRoute("SubmitScheduleVisit",
"api/SubmitScheduleVisit",
new { controller = "FindACenter", action = "SubmitScheduleVisit" },
new { httpMethod = new HttpMethodConstraint("POST") }
);
It's in the same controller. This is the action definition:
[HttpPost]
public ActionResult SubmitScheduleVisit(string selectedDate, string selectedTime, string firstName, string lastName,
string emailAddress, string phoneNumber, string whenToStart, List<string> childDatesOfBirth)
{
....
}
SOLUTION TO UPDATE (Not a solution to the original question): I simply had to run the query in Postman. I was testing the API call in Firefox which meant it was getting run as a GET, not a POST. Solved.
Global.asax
that I need to run the RegisterRoutes()? I thought that was web forms only? I added that and call RegisterRoutes() and no difference