This 404 seems unavoidable - what am I doing wrong? [Ninject 2.0 with ASP.NET MVC 2 on .NET 4]

266 views Asked by At

I downloaded the fairly new Ninject 2.0 and Ninject.Web.Mvc (targeting mvc2) sources today, and successfully built them against .NET 4 (release configuration). When trying to run an application using Ninject 2.0, i keep getting 404 errors and I can't figure out why.

This is my global.asax.cs (slightly shortified, for brevity):

using ...
using Ninject;
using Ninject.Web.Mvc;
using Ninject.Modules;

namespace Booking.Web
{
    public class MvcApplication : NinjectHttpApplication
    {        
        protected override void OnApplicationStarted()
        {
            Booking.Models.AutoMapperBootstrapper.Initialize();
            RegisterAllControllersIn(Assembly.GetExecutingAssembly());
            base.OnApplicationStarted();
        }

        protected void RegisterRoutes(RouteCollection routes)
        {
            ...
            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Entry", action = "Index", id = "" }
            );    
        }

        protected override IKernel CreateKernel()
        {
            INinjectModule[] mods = new INinjectModule[] {...};
            return new StandardKernel(mods);
        }
    }
}

The EntryController exists, and has an Index method that simply does a return View(). I have debugged, and verified that the call to RegisterAllControllersIn() is executed. I have also tried to use Phil Haacks Routing debugger but I still get a 404.

What do I do to find the cause of this?

1

There are 1 answers

2
Ben Scheirman On BEST ANSWER

Are your routes being registered? Is that being called from the base class?

Also make sure that you are registering your controllers properly. I'm not sure how Ninject's controller factory expects it, but it might require a specific name or something.