的WebAPI route返回不在果园发现模块 [英] WebApi Route returns Not Found in Orchard Module

查看:218
本文介绍了的WebAPI route返回不在果园发现模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个果园模块,在这里我要添加的WebAPI控制器。

I am creating an Orchard module where i want to add a WebApi controller.

我Module.txt:

My Module.txt:

Name: ModuleName
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 1.0
OrchardVersion: 1.0
Description: Description for the module
Features:
    ModuleName:
        Description: Description for feature ModuleName.

我添加了一个ApiRoutes类:

I have added an ApiRoutes class:

using Orchard.Mvc.Routes;
using Orchard.WebApi.Routes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

namespace ModuleName
{
    public class ModuleNameApiRoutes : IHttpRouteProvider
    {

        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
            {
                routes.Add(routeDescriptor);
            }
        }

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {
                new HttpRouteDescriptor {
                    Name = "ModuleName",
                    Priority = 5,
                    RouteTemplate = "api/modulename/{controller}/{id}",
                    Defaults = new {
                        area = "ModuleName",
                        id = RouteParameter.Optional
                    }
                }
            };
        }
    }
}

然后,我增加了一个apicontroller:

Then i have added an apicontroller:

using Newtonsoft.Json.Linq;
using Orchard;
using Orchard.Data;
using ModuleName.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace ModuleName.Controllers
{
    public class ConsumptionController : ApiController
    {
        public IOrchardServices Services { get; private set; }
        private readonly IRepository<Vessel_ConsumptionPartRecord> _repository;
        public ConsumptionController(IOrchardServices orchardServices,IRepository<Vessel_ConsumptionPartRecord> repository)
        {
            _repository = repository;
        }

        // GET: Home
       public HttpResponseMessage Get()
        {

            ...
        }


    }
}

我在本地主机和家庭地址是:

I am on Localhost and the home url is:

的http://本地主机:30321 / OrchardLocal

当我去

的http://本地主机:30321 / OrchardLocal / API /模块名/消费

我得到一个找不到网页。

I get a Not Found page.

任何人都可以提供一些线索?

Can anyone shed some light?

推荐答案

您GET方法没有一个参数ID。这可能是它

Your GET method does not have a parameter id. That might be it

这篇关于的WebAPI route返回不在果园发现模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆