簡體   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