【发布时间】:2014-03-16 16:21:16
【问题描述】:
我已将config.Formatters.Remove(config.Formatters.XmlFormatter); 添加到 ASP.NET Web API 项目中 WebApiConfig.cs 的 Register 方法中。当发生 404 Not Found 异常时,这可以很好地返回 JSON。我收到如下消息:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:2034/api/dfdf'.","MessageDetail":"No type was found that matches the controller named 'dfdf'."}
是否可以覆盖此消息以返回自定义消息?如果是这样,它是如何完成的?我正在使用 Web API 2。
【问题讨论】:
标签: c# json asp.net-web-api