gpt4 book ai didi

c# - WebApi 路由返回 Not Found in Orchard Module

转载 作者:太空狗 更新时间:2023-10-29 23:38:17 25 4
gpt4 key购买 nike

我正在创建一个 Orchard 模块,我想在其中添加一个 WebApi Controller 。

我的模块.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 类:

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:

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()
{

...
}


}
}

我在 Localhost 上,主页 URL 是:

http://localhost:30321/OrchardLocal

当我去

http://localhost:30321/OrchardLocal/api/ModuleName/Consumption

我收到“未找到”页面。

任何人都可以解释一下吗?

最佳答案

您的 GET 方法没有参数 ID。可能是这样

关于c# - WebApi 路由返回 Not Found in Orchard Module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30318514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com