All ASP.NET Web API controllers return 404

前端 未结 19 1704
臣服心动
臣服心动 2020-12-08 01:48

I\'m trying to get an API Controller to work inside an ASP.NET MVC 4 web app. However, every request results in a 404 and I\'m stumped. :/

I have th

19条回答
  •  感动是毒
    2020-12-08 02:19

    For reasons that aren't clear to me I had declared all of my Methods / Actions as static - apparently if you do this it doesn't work. So just drop the static off

    [AllowAnonymous]
    [Route()]
    public static HttpResponseMessage Get()
    {
        return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
    }
    

    Became:-

    [AllowAnonymous]
    [Route()]
    public HttpResponseMessage Get()
    {
        return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
    }
    

提交回复
热议问题