Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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# 在IIS7上托管WebAPI时出错:未找到与请求URI匹配的HTTP资源_C#_Asp.net Mvc 4_Asp.net Web Api - Fatal编程技术网

C# 在IIS7上托管WebAPI时出错:未找到与请求URI匹配的HTTP资源

C# 在IIS7上托管WebAPI时出错:未找到与请求URI匹配的HTTP资源,c#,asp.net-mvc-4,asp.net-web-api,C#,Asp.net Mvc 4,Asp.net Web Api,我的控制器中有如下代码: [ActionName("GetAllProducts")] public IEnumerable<Product> GetAllProducts() { return repository.GetAllProducts(); } 但在主持IIS7之后,我开始关注以下问题 <Error> <Message> No HTTP resource was found

我的控制器中有如下代码:

 [ActionName("GetAllProducts")]
        public IEnumerable<Product> GetAllProducts()
        {
            return repository.GetAllProducts();
        }
但在主持IIS7之后,我开始关注以下问题

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

未找到与请求URI名称匹配的HTTP资源http://localhost/ProductsWebAPI/api/GetAllProducts'.
找不到与名为“GetAllProducts”的控制器匹配的类型。

请帮我解决这个问题。

您可能会在默认路线之前添加一条路线:

            config.Routes.MapHttpRoute(
                name: "GetAllProducts",
                routeTemplate: "api/{controller}/{action}"
            );

你不应该指向
api/Products/getallproducts
            config.Routes.MapHttpRoute(
                name: "GetAllProducts",
                routeTemplate: "api/{controller}/{action}"
            );