Use*_*999 6 c# asp.net-web-api
让我先描述一下情况:
我有一个基本的控制器,看起来像这样:
public class SearchRequestController : ApiController
{
public IEnumerable<ObjectA> GetAllRequests() {...}
{}
public IEnumerable<ObjectA> GetLatestRequest() {...}
{}
}
Run Code Online (Sandbox Code Playgroud)
使用以下路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
我可以轻松地使用如下功能
Http://myServer/myvirtualdirectory/api/SearchRequest/GetAllRequests
Http://myServer/myvirtualdirectory/api/SearchRequest/GetLatestRequest
Run Code Online (Sandbox Code Playgroud)
现在我想添加以下控制器
public class UserController : ApiController
{
public IEnumerable<UserObject> SearchUsersByInput() {...}
}
Run Code Online (Sandbox Code Playgroud)
但是以下GET不起作用
Http://myServer/myvirtualdirectory/api/User/SearchUsersByInput
I'm getting a 405: {"Message":"The requested resource does not support http method 'GET'."}
Run Code Online (Sandbox Code Playgroud)
但是当我改变我的功能时,它可以工作如下:
public class UserController : ApiController
{
[HttpGet]
public IEnumerable<UserObject> SearchUsersByInput() {...}
}
Run Code Online (Sandbox Code Playgroud)
问题: 有人可以解释这种行为的起源吗?我做错了什么或者我的路由有问题吗?
| 归档时间: |
|
| 查看次数: |
916 次 |
| 最近记录: |