繁体   English   中英

ASP.NET Web-API OWIN:找不到与请求URI匹配的HTTP资源

[英]ASP.NET Web-API OWIN: No HTTP resource was found that matches the request URI

在此站点上一些用户的帮助下,我使测试应用程序正常运行,现在开始编写所需的实际应用程序。

我有一个使用OWIN承载ASP.NET Web API的C#应用​​程序。 我需要该应用程序来提供有关其他打开的应用程序的信息。 我编写的程序几乎与我工作的测试/示例程序完全相同,但是更改了一些名称。

当我尝试访问` http:// localhost:9000 / api / applications时 ,出现错误消息:

<Error>
  <Message>
    No HTTP resource was found that matches the request URI 'http://localhost:9000/api/applications'.
  </Message>
  <MessageDetail>
    No type was found that matches the controller named 'applications'.
  </MessageDetail>
</Error>

`Server类是主要类:

namespace Server
{
    public class Server
    {
        public const string baseAddress = "http://localhost:9000/";
        static void Main(string[] args)
        {
            ApplicationManager.getManager().AddApplication(new Application(1, "Chrome", 0.5f));
            ApplicationManager.getManager().AddApplication(new Application(2, "Windows Media Player", 1.0f));
            ApplicationManager.getManager().AddApplication(new Application(3, "Minecraft", 1.0f));

            using (WebApp.Start<Startup>(url: baseAddress))
            {
                Console.ReadKey();
            }

        }
    }
}

这是我的Web API配置类:

namespace Server
{
    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            appBuilder.UseWebApi(config);
        }
    }
}

这是我的控制器:

namespace Server.Api.Controllers {
    public class ApplicationController : ApiController
    {
        public IEnumerable<Application> Get()
        {
            return ApplicationManager.getManager().GetApplications();
        }

        public IHttpActionResult Get(int id)
        {
            Application app = ApplicationManager.getManager().GetApplication(id);
            if (app == null)
            {
                return NotFound();
            }

            return Ok(app);
        }
    } }

Application对象仅包含一些属性和构造函数。 ApplicationManager类仅将应用程序添加到控制器使用的应用程序列表中。

http://localhost:9000/api/applications替换为http://localhost:9000/api/application 最后一个字母s导致了此问题。 希望这可以帮助!

我也面临着这个问题。 经过很多努力后,我意识到我的Controller类是私有的,这导致了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM