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}"
);