I'm working on an ASP.NET MVC app. I have been using just the default routing rule. I have a number of views that render forms using code like this:
@using (Html.BeginForm("ForgotPassword", "Register", FormMethod.Post))
This has been working fine. The form action would post to /myapp/register/forgotpassword
and everything works great.
Now need to add some service endpoints into the same application. So I added some new routes above the default one. The routing setup now looks like:
//New rule
RouteTable.Routes.Add(
new ServiceRoute(
"api/user", new MyCustomerServiceHostFactory(),
typeof(UserWebservice)));
//Default rule
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
After I added the new rule all my forms broke. Inspecting the HTML, I can see that the form action is /myapp/api/user?action=ForgotPassword&controller=Register'
, which is totally wrong.
So my question is: how do I route the new service without breaking all my existing forms?
And for bonus points: what the heck is going on here?