Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET WebAPI Selfhost没有';无法解析到控制器的路由_C#_Asp.net_Asp.net Mvc_Asp.net Web Api - Fatal编程技术网

C# ASP.NET WebAPI Selfhost没有';无法解析到控制器的路由

C# ASP.NET WebAPI Selfhost没有';无法解析到控制器的路由,c#,asp.net,asp.net-mvc,asp.net-web-api,C#,Asp.net,Asp.net Mvc,Asp.net Web Api,我正在使用版本为“5.0.0-rc1”的“Microsoft.AspNet.WebApi.SelfHost”NuGet软件包(也尝试了当前的稳定版本),但不幸的是,我无法让我的应用程序设置解析到我的ApiController实现的配置路由 该应用程序非常简单,几乎可以在所有示例中找到。它包含一个.NET控制台应用程序,其中自主机服务位于主类中 using System.Web.Http.SelfHost; using System.Web.Http; using System; namespac

我正在使用版本为“5.0.0-rc1”的“Microsoft.AspNet.WebApi.SelfHost”NuGet软件包(也尝试了当前的稳定版本),但不幸的是,我无法让我的应用程序设置解析到我的ApiController实现的配置路由

该应用程序非常简单,几乎可以在所有示例中找到。它包含一个.NET控制台应用程序,其中自主机服务位于主类中

using System.Web.Http.SelfHost;
using System.Web.Http;
using System;
namespace EP.Server
{
class Program
{
    static void Main(string[] args)
    {
        var config = new HttpSelfHostConfiguration("http://localhost:60064");
        config.Routes.MapHttpRoute(
            name: "Default Route",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        using (var server = new HttpSelfHostServer(config))
        {
            server.OpenAsync().Wait();
            Console.WriteLine("Server ist running on "+config.BaseAddress + " hit ENTER to stop.");
            Console.ReadLine();
            server.CloseAsync().Wait();
        }
    }
}
}
还有一个单独的控制器类,它位于同一个项目中,并从ApicController类继承

using System.Web.Http;

namespace EP.Server
{
class UsersController : ApiController 
{
    [HttpGet]
    public string Get()
    {
        return "Hello I'm a user...";
    }
}
}
当我从任何浏览器调用服务时,错误消息听起来都是这样的

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

未找到与请求URI名称匹配的HTTP资源http://localhost:60064/api/Users'.
找不到与名为“Users”的控制器匹配的类型。
有人知道那里出了什么问题吗?不幸的是,我在网上找不到任何类似的问题


谢谢大家

Web API控制器必须是公共的

哦,当然,它们应该是公共的,然后一切正常。怪我…嘿,菲利普,谢谢你的提示。这很有趣,因为我从你的博客上读到了你的howto,你的回答很酷。我可以再问一个问题吗?我现在扩展了我的项目,包括来自外部库的服务。我现在想要实现的是,我希望在不重新启动WebAPI核心服务的情况下设置新服务。我想检查AppConfig中的新服务,并在需要时加载它们。不幸的是,我还没有找到实现这一目标的方法。您能提供一个解决方案吗?在这里也是一样,但是我的控制器已经是公共的,并且错误仍然存在…:(