I have a bunch of custom routes defined using AttributeRouting. I have a function in a controller that is trying to access one of these API functions at /api/GetBatchItems.
GetBatchItems is a function of the controller APIController, similar to:
[RouteArea("api")]
public sealed class APIController : ApiController{
[GET("GetBatches")]
public IEnumerable<PRAT.Models.EF.EFBatchItem> GetBatches() { ... }
}
In another controller, I am trying to get the result. When browsing directly everything is fine if I do it this way, but I want to be able to use my already defined route, is there a way to do that? I saw someone mention HttpAttributeRoutingConfiguration
but I could not find that class anywhere. I don't want to have to use the MapHttpRoute
method this way...
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("default", "api/{controller}/{id}", null);
var server = new HttpServer(config);
var client = new HttpClient(server);
string url = Request.Url.GetLeftPart(UriPartial.Authority) + "/api/APIController/GetBatches";
var result = client.GetAsync(url).Result;
var content = result.Content;
var model = content.ReadAsAsync<IEnumerable<PRAT.Models.EF.EFBatchItem>>().Result;
if (model == null) return View();
else return View(model);