步骤:
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
答案 0 :(得分:3)
确保您的控制器类继承自ApiController
。
(确切地说:您的控制器不一定必须来自ApiController
,但必须实现IHttpController
。大部分时间是通过子类ApiController
实现的,虽然。)