ActionLink behavior with ASP.NET WCF and Routes.Add in MVC application

466 views Asked by At

I'm want to host both WCF 4 and MVC 3 in my C#.Net project. But when I add the service paths for WCF, Html.ActionLink starts creating a wrong url for MVC app. My route table is created as:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

RouteTable.Routes.Add(new ServiceRoute("api1/projects", new WebServiceHostFactory(), typeof(Projects)));
routes.MapRoute(
   "Default", // Route name
   "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Above route table creates the right access paths to both the WCF and MVC applications, but Html.ActionLink creates the edit links as

http://localhost:8000/api1/projects?action=Edit&controller=technology&id=2 

instead of

http://localhost:8000/technology/Edit/2

If I omit the line starting with RouteTable.Routes.Add, the ActionLink works as expected (and of course not the WCF). How can I add the WCF routes and make sure actionlink behaviour doesn't change?

1

There are 1 answers

1
Jakub Konecki On

Try putting ServiceRoute registration after MapRoute.