I have used attribute routing and set a RoutePrefix() as the default route of FirstController. Then i have created a new controller and gave its default route.
A compile time System.ArgumentException is generating on "GlobalConfiguration.Configure(WebApiConfig.Register);" in Global.asax showing Message: "A path segment cannot contain two consecutive parameters. They must be separated by a or by a literal string."
This is FirstController.cs
[System.Web.Http.RoutePrefix("api/First")]
public class FirstController : ApiController
{
[System.Web.Http.HttpGet]
[System.Web.Http.Route("Method1")]
public int Method1(string Param1, string Param2)
{
}
[System.Web.Http.HttpGet]
[System.Web.Http.Route("Method2")]
public int Method2(string Param1, string Param2)
{
}
}
This is SecondController.cs
[System.Web.Http.RoutePrefix("api/Second")]
public class SecondController : ApiController
{
[System.Web.Http.HttpGet]
[System.Web.Http.Route("Method3")]
public int Method3(string Param1, string Param2)
{
}
[System.Web.Http.HttpGet]
[System.Web.Http.Route("Method4")]
public int Method4(string Param1, string Param2)
{
}
}
And this is my Global.asax (returning data in JSON)
protected void Application_Start()
{
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
I'm trying to create multiple controllers having their own default routes. Please help.
What I have tried:
I've searched for the solutions but their is no specific answer regarding this problem.
I've found on answer that "As it is Web API doesn't support multiple identical attribute routes on different controllers. You will get a 404, because all the route matches more than one controller and at that point Web API will consider the result ambiguous. Note that MVC 6 does not have this limitation (but as this point it is not RTM yet).
However if you use Web API 2.11 (or newer) you can create a route constraint for the http method per controller and use it instead of the built in Route Attribute."