请注意,本站并不支持低于IE8的浏览器,为了获得最佳效果,请下载最新的浏览器,推荐下载 Chrome浏览器
欢迎光临。交流群:166852192

WebAPI actions in Orchard


Building WebAPI controllers in Orchard is fairly simple: just inherit from System.Web.Http.ApiController. You’ll then be able to inject dependencies exactly in the same way that you would anywhere in Orchard. WebAPI is designed so that the default behavior is that a controller represents a category of resources, such as a product, an article, etc. There’s a bunch of conventions in place so that just naming the methods on the controllers is enough to wire them up. If this REST-like behavior is what you’re after, that’s great, just apply the conventions and you’re good to go. If you need to stray from that model, and implement something closer to what you’d do with a regular MVC controller, you’ll need to do a little more work.
First, you’ll need to make sure that there’s a route that’s able to point to your actions, or create one. The default routes for WebAPI in Orchard look like “api/{module.name}/{controller}/{id}”. Notice how there’s no action in that route. That’s because the system figures out what action to use based on the conventions I was talking about in the previous paragraph.
Outside of the conventions, you will need to have a proper route, and you’ll need to spell out to the system what verb the action should answer to:
[AcceptVerbs()]
 HttpResponseMessage Content() {
And that’s pretty much it. There are a few more things to know about WebAPI, but they are not specific to Orchard…



作者原创内容不容易,如果觉得内容不错,请点击右侧“打赏”,赏俩给作者花花,也算是对作者付出的肯定,也可以鼓励作者原创更多更好内容。
更多详情欢迎到QQ群 166852192 交流。