c# - How to add a Web API service to a non-MVC Asp site? -
with of several online tutorials, this one, still struggling add web api service existing asp site, not mvc.
i added project new item of type web api controller class(v2.1), named abccontroller.cs, , vs2015 asked me put in app_code directory. default code has handlers get, put etc. sounded me on right track.
i added default route in global.asax.cs in tutorial:
routetable.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } );
this got built after adding reference system.web.http.webhost not mentioned in tutorial. sounded still on right track.
however, doesn't work. run site in debug , gives me 404 not found:
http://localhost:54905/api/abc
i tried run on production server iis7, of course second test web site not interfere version in production. however, ran error microsoft.web.infrastructure dll not found. fix this, should install mvc packages, don't experiment.
my questions are:
do right url in lower case, i.e., not .../api/abc ?
does kind of routing work in debugger?
am turning web site mvc web site?
is simplest way add "rest" service existing web site? need implement post, read , return json data, , not need arguments in url
Comments
Post a Comment