2

I have a ASP.NET MVC application in VS 2010. I added a new Web API Controller to my application. Here is the simple method I am trying to call:

 public List<Article> Get()
        {
            using (var db = new HighOnCodingDbEntities())
            {
                var articles = (from a in db.Articles
                               select a).Take(10).ToList();
                return articles; 
            }

        }

Global.asax:

routes.MapHttpRoute(
    name: "API Default",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

When I call this method I get "Resource Not Found". I have published the application binary to the production and I believe that is all I need to do.

URL should be: http://www.highoncoding.com/api/articlesapi

ArticlesAPIController.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using HighOnCoding.Models;

namespace HighOnCoding.Controllers
{
    public class ArticlesAPIController : ApiController
    {
        // GET api/<controller>
        public List<Article> Get()
        {
            using (var db = new HighOnCodingDbEntities())
            {
                var articles = (from a in db.Articles
                               select a).Take(10).ToList();
                return articles; 
            }

        }

        // GET api/<controller>/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/<controller>
        public void Post(string value)
        {
        }

        // PUT api/<controller>/5
        public void Put(int id, string value)
        {
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
        }
    }
}

Works on local machine:

enter image description here

7
  • How have you defined the route? What URL are you calling? Honestly how do you think we could answer 404 question not knowing these details? Commented Jul 5, 2012 at 16:43
  • updated the question with additional information! Commented Jul 5, 2012 at 17:12
  • How's the controller containing this method called? Commented Jul 5, 2012 at 17:24
  • I just visit the URL: highoncoding.com/api/articlesapi and that is it. IT does not display the results. Commented Jul 5, 2012 at 17:52
  • Yes, I can see that it does not display any results. That's what we are trying to help you with. So I repeat my question: How's the controller class containing this method called? Commented Jul 5, 2012 at 18:02

1 Answer 1

2

In production, ensure that the .NET Framework version for your IIS7 Application Pool for your website is set to .NET 4.0.xxx in integrated mode.

Sign up to request clarification or add additional context in comments.

1 Comment

Seems like the hosting provider currently does not allow the MVC 4 BETA version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.