我已经在mvc中创建了这个webapi,你可以在这里看到:
namespace WebUI.Areas.Administrator.Controllers
{
public class MemberApiController : ApiController
{
private IMemberRepository _iMemberRepository;
private IJobRepository _iJobRepository;
private IEducationRepository _iEducationRepository;
// GET: Administrator/Member
public MemberApiController(IMemberRepository imemberRepository)
{
_iMemberRepository = imemberRepository;
}
[HttpGet]
public Member Get(int id)
{
return _iMemberRepository.Get().Where(i=>i.Id==id).First();
}
}
}
正如您所见,我的api是在administrator area
中创建的。但是当我调用此网址http://localhost:5542/Api/administrator/memberApi?Id=1
时。我收到此错误:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Api/administrator/memberApi
我的api配置
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}