我主持了一个自托管的WebApi,但我正在努力使用路由。我想我配置得很好,但结果仍然是404:
这是我的配置:
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional,
controller = "Values", action = "Index", });
服务器初始化:
string baseAddress = "http://localhost:1243";
var configuration = new HttpSelfHostConfiguration(baseAddress);
WebApiConfig.Register(configuration);
_server = new HttpSelfHostServer(configuration);
_server.OpenAsync().Wait();
那是我的控制器:
public class ValuesController : ApiController
{
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
在我的浏览器中,我试图导航: