asp.net mvc - Web API 2 routing fails for literal segment -


i'm facing issue web api 2 routing literal segments.

in 1 project, have asp.net mvc , webapi2 running together, project running mvc areas.

under each area, there api folder contains apis. i'm facing issue when trying request following url: {host}/accesscontrol/api/reporting/bookings.

  • accesscontrol here area name
  • reporting controller
  • bookings literal segment.

the error i'm getting: no action found on controller 'reporting' matches request.

this controller should receive request:

[routeprefix("accesscontrol/api/reporting")] public class reportingcontroller : apicontroller {     [route("bookings")]     [responsetype(typeof(booking))]     [httpget]     public async task<ihttpactionresult> bookings(string q = null)     {         //code data         return ok(bookings);     } } 

when remove [route('bookings')] attribute, request working regardless if bookings segment there or not.

this configuration of routing under area registration class:

public override void registerarea(arearegistrationcontext context) {     context.routes.maphttproute(         "accesscontrolapi_default",         "accesscontrol/api/{controller}/{id}",         new { id = routeparameter.optional }         );      context.maproute(         "accesscontrol_default",         "accesscontrol/{controller}/{action}/{id}",         new { action = "index", id = urlparameter.optional }     ); } 

how can let app understand literal segments under areas?

edit

i'm calling registerallareas in global.asax.cs file, follow:

public class mvcapplication : system.web.httpapplication {     protected void application_start()     {         arearegistration.registerallareas();         globalconfiguration.configure(webapiconfig.register);         filterconfig.registerglobalfilters(globalfilters.filters);         routeconfig.registerroutes(routetable.routes);         bundleconfig.registerbundles(bundletable.bundles);     } } 

i managed make work add action after controller in maphttproute , change [route("bookings")] attribute [actionname("bookings")] , works.

  context.routes.mapmvcattributeroutes();    context.routes.maphttproute(       "accesscontrolapi_default",       "accesscontrol/api/{controller}/{action}/{id}",       new { id = routeparameter.optional}); 

i hope out.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -