16

My case is very similar to this question, but since he did not get an answer I thought I'd throw some more input.

Everything works fine locally (on the VS embedded server). When I deploy to Azure, I get a 404 error accompanied by "No type was found that matches the controller named...".

However, when I load the routedebugger module the mapping seems ok even on Azure.

What can I do to debug that problem?

Thanks,

Alex

Edit: my routes are created this way:

            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            };
            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "ActionApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Edit 2: Here my controller class

    public class EmployeeController : ApiController
{
    // GET api/<controller>
    public IEnumerable<Employee> Get()
    {
        using (var context = new nws())
        {
            return context.Employees;
        }
    }

    // GET api/<controller>/5
    public Employee Get(int id)
    {
        using (var context = new nws())
        {
            return context.Employees.FirstOrDefault(e => e.ID == id);
        }
    }

    // GET api/<controller>/getbyatid/5
    public Employee GetByAtId(string id)
    {
        using (var context = new nws())
        {
            return context.Employees.FirstOrDefault(e => e.AtUserID == id);
        }
    }

    // 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)
    {
    }

    // GET api/<controller>/timebank/5
    public int? GetTimeBank(string id)
    {
        using (var context = new nws())
        {
            var employee = context.Employees.FirstOrDefault(e => e.AtUserID == id);
            if (employee != null)
                return employee.GetTimeBank();
            return null;
        }
    }
}
Community
  • 1
  • 1
alexbilo
  • 163
  • 1
  • 5
  • Are you using any IoC container to resolve your controllers? – nemesv Jan 24 '13 at 06:00
  • no, the controller is a standard class and I create the routes in application_start using the code in the edit above. – alexbilo Jan 24 '13 at 16:21
  • Well, the same as in the linked to question: is there any chance that MVC is not properly deployed to Azure? – sharptooth Jan 25 '13 at 08:07
  • can you please supply your working local url, the url you are trying to access on azure, and let us know how you are deploying to azure. is it a website, web role, vm... thanks – felbus Jan 25 '13 at 12:14
  • @Felbus : working: http://localhost:2274/api/employee now working: http://myazuredomain.azurewebsites.net/api/employee and I deploy to an Azure web site. – alexbilo Jan 25 '13 at 20:50
  • @sharptooth : there are many chances, how can I verify that? – alexbilo Jan 25 '13 at 20:52
  • everything should be ok. how are you deploying? git? web matrix? from vs using publish? did you auto generate the api controller from the employee class? just trying to get a better picture, theres not much info to go on.. thanks – felbus Jan 26 '13 at 09:43
  • @Felbus I use vs to publish, I previously downloaded the publish profile from the Azure web site. I included my web api controller class in the original post – alexbilo Jan 26 '13 at 14:52
  • @alexbilo: You can rename the service package to have .zip extension and just unpack it and see what's inside. – sharptooth Jan 28 '13 at 06:25
  • @sharptooth: my azure hosting being a web site, I don't have a service package (like you'd have if deploying a "cloud service" or a web role). Can I deploy those web api services to an Azure web site? – alexbilo Jan 28 '13 at 16:34
  • I am not gonna put this as an answer, but to get things moving I found that [attributerouting](http://attributerouting.net/) works well, plus it's a much nicer way to write routes! – alexbilo Jan 29 '13 at 02:51
  • One test that can help you to better understand the problem is to deploy your web site on a local iis. – Davide Icardi Mar 19 '13 at 22:17
  • If you are using Explorer 9, you can see the HTTP request and request messages by using the F12 developer tools in Internet Explorer 9. Then you select the Network tab and press Start Capturing and reload your web page by pressing F5. Select the item for the relative URI and click 'Detailed view' to see the request and response headers and bodies. – Only You Mar 20 '13 at 13:51
  • 2
    alexbilo, if I understand right, you are self-hosting your web api. If that's the case, I noticed this note "If you self-host Web API, you must set the routing table directly on the HttpSelfHostConfiguration object." on this page http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api – Only You Mar 20 '13 at 14:05

1 Answers1

1

Switch the order of routes and try again.

        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        };
Syam
  • 1,629
  • 1
  • 20
  • 32