我的API控制器永远不会被实例化,即使我已根据this和this问题多次确定我的路由应该是正确的。
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseWebApi(config);
}
这就是我的控制器的样子:
class RaspberryController : ApiController
{
public HttpResponseMessage Get()
{
return new HttpResponseMessage
{
Content = new StringContent("Test from Owin")
};
}
}
你可以看到它非常简单。什么可能是错的?
答案 0 :(得分:0)
I realized that my controller class were implicitly internal
since I didnt specify otherwise. It must be public
in order for Owin to find the class by reflection. Thus it had nothing to do with routing...
public class RaspberryController : ApiController
{
public HttpResponseMessage Get()
{
return new HttpResponseMessage
{
Content = new StringContent("Test from Owin")
};
}
}