asp.net web api2 - Web Api call not reaching action? -


i have webapiconfig setup this:

  public static class webapiconfig {     public static void register(httpconfiguration config)     {         config.maphttpattributeroutes();          config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{controller}/{id}",             defaults: new { id = routeparameter.optional }         );     } } 

i have registered route in global.asax follows:

protected void application_start()     {         arearegistration.registerallareas();         filterconfig.registerglobalfilters(globalfilters.filters);         routeconfig.registerroutes(routetable.routes);         bundleconfig.registerbundles(bundletable.bundles);         webapiconfig.register(globalconfiguration.configuration);     } 

my web api controller class looks this:

[routeprefix("api/upload")] public class uploadcontroller : apicontroller {     [httpget]     [route("")]     public string upload()     {         return "hello";     } } 

i'm making call web api action in fiddler shown in image below:

enter image description here

i'm getting 404 not found not found error when send request. doing wrong?

try configure web api before mvc route mappings:

protected void application_start() {     webapiconfig.register(globalconfiguration.configuration);     arearegistration.registerallareas();     filterconfig.registerglobalfilters(globalfilters.filters);     routeconfig.registerroutes(routetable.routes);     bundleconfig.registerbundles(bundletable.bundles); } 

what believe happening framework trying map route mvc one. assuming uri localhost:8170/api/upload referring mvc controller called api action named upload.

registering web api routes before mvc allow framework match routes starting api/ correct apicontroller.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -