简体   繁体   English

Web API 2属性路由不起作用

[英]Web API 2 Attribute Routing Not working

I Have this API method: 我有这个API方法:

 public class UsersController : ApiController
{

    [HttpGet]
    [Route("Users")]
    string GetUsers()
    {
        return "Aye";
    }
} 

And this routing in config: 这个配置中的路由:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.MapHttpAttributeRoutes();
    }
}

I host the API on IIS (localhost:8000) , give the site all the required permissions and when I try to call http://localhost:8000/Users it says: 我在IIS(localhost:8000)上托管API,为网站提供所有必需的权限,当我尝试调用http:// localhost:8000 / Users时,它说:

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. HTTP错误404.0 - 未找到您要查找的资源已被删除,名称已更改或暂时不可用。

Please help. 请帮忙。

控制器操作应该定义为public ,但是你没有访问修饰符,所以它是内部的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM