我正在使用Ninject作爲我的依賴注入框架的ASP.NET MVC 3.0應用程序。獲取「無法找到資源」。錯誤,當使用Ninject
所以,我繼承了我的NinjectHttpApplication控制器,像這樣:
public class MvcApplication : NinjectHttpApplication
{
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
}
protected void Application_Start()
{
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
AreaRegistration.RegisterAllAreas();
DependencyResolver.SetResolver(new NinjectDependencyResolver(Kernel));
}
protected override Ninject.IKernel CreateKernel()
{
return new StandardKernel(new QueriesModule());
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "Home", action = "Index" },
new string[] { typeof(HomeController).Namespace }
);
}
}
但每當我運行應用程序並嘗試瀏覽到我的任何控制器,我得到的錯誤:
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: /Home/Index
這是什麼原因造成的?我該如何解決?