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:
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
Post a Comment