Web API“2”模板,属性路由在构建时返回404

时间:2013-09-30 13:50:41

标签: asp.net-web-api visual-studio-2013

步骤:

1. Create empty project, click checkbox for Web API and Test project 
   (probably optional)
2. In WebApiConfig.cs, clear out Register contents, set to 
   config.MapHttpAttributeRoutes();
3. Create Controller:

   public class TestController
   {
       [HttpGet("test")]
       public string GetVal()
       {
             return "Testing";
       }
   }
4. Build and run project
5. Open Fiddler/Postman/etc and go to localhost:port/test -> 404

有谁能告诉我如何使这个特定部分有效?

编辑:

应该声明服务器默认为IIS 8.0 Express

1 个答案:

答案 0 :(得分:3)

确保您的控制器类继承自ApiController

(确切地说:您的控制器不一定必须来自ApiController,但必须实现IHttpController。大部分时间是通过子类ApiController实现的,虽然。)