routes - Web Api 2 - No HTTP resource was found that matches the request URI -


i have mvc project in solution, has apicontrollers in it. have set project in iis , added hosts file.

the route looks this:

globalconfiguration.configuration.routes.maphttproute(         name: "defaultapi",         routetemplate: "api/{controller}/{action}/{id}",         defaults: new { id = routeparameter.optional }); 

i added controller called testcontroller inside folder project.web/controllers , has 1 method, return string this:

public class testcontroller : apicontroller {     public string get()     {         return "test";     } } 

if try reach site via mysite.local/api/test/get following error:

{ "message": "no http resource found matches request uri 'http://mysite.local/api/test/get'.", "messagedetail": "no type found matches controller named 'test'." }

but if start website visual studio 17, able reach localhost:portnr/api/test/get without errors.

i have tried add [route()] , [routeprefix()] without success have tried move apicontroller project.web/controllers/api without success

does know why able reach via localhost, not via domainname?

regards david

you don't need pass name hen have action method name get.

you need revert change in rout config default configuration, if wish use custom routing please use route annotation.

    config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{controller}/{id}",             defaults: new { id = routeparameter.optional }         ); 

api understand default, if got url "http://sampleweb.com/api/test" call method.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -