3

I'm trying to convert the existing web project to MVC. I made a standard MVC project in VS 2012. It added routing configuration. My existing project already contained routing entry used by WCF services. So now routes are configured like this:

// Was here before, used by services
routes.Add(new ServiceRoute("AppServer", new WebServiceHostFactory(), typeof(MyService)));

// the rest is added by vs to configure a default controller
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

I realized that service part should always go first because it is more restrictive. Service doesn't work if it is put to the end. But now the problem is that

@Html.ActionLink("text", "MyAction", "MyController")

now generates me the links of type

http://localhost/AppServer?action=MyAction&controller=My

instead of

http://localhost/My/MyAction

what I would expect.

Does anyone know how to make service route and mvc-related routes "live in peace" i.e. not to affect each other?

Prasanth
  • 5,230
  • 2
  • 29
  • 61
ElDog
  • 1,230
  • 1
  • 10
  • 21
  • 1
    Try put the MapRoute on top but add a fourth parameter for contraints, like this `new { controller = "regex-for-!=-AppServer" }` – Tallmaris Oct 23 '12 at 18:53
  • Tallmaris: thank you, this works! If you put it as an answer, I would mark it. – ElDog Oct 23 '12 at 19:39
  • I ended up using WcfContraint from this solution http://stackoverflow.com/questions/7225887/wcf-web-api-service-routes-conflicting-with-regular-asp-net-mvc-routes-web-api – Maksim Vi. Oct 04 '13 at 23:03

1 Answers1

2

Try and put the MapRoute on top but add a fourth parameter for contraints, like this:

new { controller = "regex-for-!=-AppServer" }

This way, when creating a link the helper will use the first route found, but still incoming requests to "/AppServer" will be skipped and processed by the ServiceRoute.

Tallmaris
  • 7,605
  • 3
  • 28
  • 58