I'm currently trying to set up a dependency nesting and override the authorization attribute. I tried to follow a few examples, although I always get errors.
Global.asax
public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication { private class MyModule : NinjectModule { public override void Load() { this.BindFilter<SageAdminAuthorizationFilter>(FilterScope.Controller, 0); Bind<IAuthentication>().To<CustomAuthenticationService>(); } } public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } protected override IKernel CreateKernel() { var modules = new INinjectModule[] { new MyModule() }; var kernel = new StandardKernel(modules); return kernel; } }
Authentication filter
public class CustomAuthenticationService : IAuthentication { public void SignIn(string claimedIdentifier, bool createPersistentCookie) {
I always get
The sequence contains no elements.
Any help would be appreciated.
Update: I am still getting the same error.
The call stack is as follows
Search for a source for 'c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs'. Checksum: MD5 {3d e3 7f 86 44 70 db 0 3c 6f e0 97 fb 1e 12 13} File 'c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs ' does not exist. Viewing documents in a script for 'c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs' ... In projects for' c: \ Projects \ Ninject \ ninject.web .mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs'. File not found in project. Browse in the directory 'C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC \ crt \ src \' ... Browse in the directory 'C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC \ atlmfc \ src \ mfc \ '... View in the directory' C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC \ atlmfc \ src \ atl \ '... View in the directory' C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC \ atlmfc \ include \ '... The parameters of the debugging source files for the active solution indicate that the debugger will not ask the user to find the file: c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs. The debugger could not find the source file 'c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs'.
I installed Ninject and Ninject.MVC3 from Nuget. It looks though it is trying to find files for debugging. Can anyone give me information on why this is happening.
I also get this error
[InvalidOperationException: The sequence contains no elements] System.Linq.Enumerable.Single (IEnumerable 1 source) +320 Ninject.Web.Mvc.Bootstrapper.Initialize(Func 1 createKernelCallback) in c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ Bootstrapper.cs: 67 Ninject.Web.Mvc.NinjectHttpApplication.Application_Start () in c: \ Projects \ Ninject \ ninject.web.mvc \ mvc3 \ src \ Ninject.Web.Mvc \ NinjectHttpApplication.cs: 65
source share