0
我託管一個自我託管的WebApi,但我正在努力與路由。我想,我配置了一切正確的,但我仍然得到404結果:自主WebApi路由問題
這是我的配置:
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" };
}
}
在我的瀏覽器中我想導航: