【发布时间】:2016-11-28 13:14:50
【问题描述】:
http://xxxx/api/garmin/data 抛出以下错误
找不到与名为“garmin”的控制器匹配的类型。
下面是Global.asax中的代码
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHttpRoute(
name: "ControllerAndAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "json", new MediaTypeHeaderValue("application/json")));
GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "xml", new MediaTypeHeaderValue("application/xml")));
}
控制器代码
public class GraminController : ApiController
{
// GET
[HttpGet]
[ActionName("data")]
public string GetGarminData()
{
return "value";
}
}
以上代码在开发服务器上运行,但抛出以下错误
未找到与请求匹配的 HTTP 资源 URI 'http://xxxx/api/garmin/data'。无类型 发现与名为的控制器匹配 '佳明'。
我做错了什么?我该如何解决这个错误?
【问题讨论】:
-
是的,在 Fiddler 中提到了 'Content-Type: application/json; charset=utf-8' 我正在尝试使一个简单的 GET 请求工作,但这也失败了。
标签: c# asp.net asp.net-web-api routing