我有一个在 Visual Studio 中创建的 ASP .Net Web 应用程序。我正在按照此处的 KendoUI 教程来创建 REST API。我相信我已经正确设置了它,但问题是当我导航到 URL 时它说找不到它。
这是我的控制器:
public class IngredientControllers : ApiController
{
private Data.RecipeTrackerDataContext _context = new Data.RecipeTrackerDataContext();
// GET api/<controller>/5
public List<Models.Ingredient> Get()
{
var ingredients = from e in _context.Ingredients
select new Models.Ingredient
{
Id = e.IngredientID,
ItemID = e.ItemID,
Amount = e.Amount
};
return ingredients.ToList();
}
// POST api/<controller>
public void Post([FromBody]string value)
{
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/<controller>/5
public void Delete(int id)
{
}
}
}
这是我的 Global.aspx 文件:
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterOpenAuth();
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional });
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
}
}