-1

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Brian Reischl
  • 7,216
  • 2
  • 35
  • 46

1 Answers1

0

try using as below,

//New rule
RouteTable.Routes.Add(
    new ServiceRoute(
    "UserWebservice", 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
  );

I think changing the code for route add as Reference link should work. Also check this blog for creating Dynamic service routes.

Community
  • 1
  • 1
Harsh Baid
  • 7,199
  • 5
  • 48
  • 92