Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4331642
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:08:23+00:00 2026-05-21T10:08:23+00:00

Currently I am trying to set up dependency injection and override the authorisation attribute.

  • 0

Currently I am trying to set up dependency injection and override the authorisation attribute. I have tried to follow a few examples although I always seem to 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)
    {
        //Write Sign in code here
        FormsAuthentication.SetAuthCookie(claimedIdentifier, createPersistentCookie);
    }

    public void SignOut()
    {
        FormsAuthentication.SignOut();
    }

    public bool Authorize(HttpContextBase httpContext)
    {
        //Check here if the user can administer the  admin
        return false;
    }
}

//The Authorization attribute on a controller
public class CustomAdminAuthorizationFilter : IAuthorizationFilter
{
    private readonly IAuthentication _authentication;

    public SageAdminAuthorizationFilter(IAuthentication authentication)
    {
        _authentication = authentication;
    }

    public void OnAuthorization(AuthorizationContext filterContext)
    {
        _authentication.Authorize(filterContext.HttpContext);
    }
}

I always receive

Sequence contains no elements.

Any help would appreciated.

Update:
I am still receiving the same error.

The call stack is as follows

Locating 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}
The file ‘c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectHttpApplication.cs’ does not exist.
Looking in script documents for ‘c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectHttpApplication.cs’…
Looking in the projects for ‘c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectHttpApplication.cs’.
The file was not found in a project.
Looking in directory ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\’…
Looking in directory ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\’…
Looking in directory ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\’…
Looking in directory ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\’…
The debug source files settings 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 locate the source file ‘c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectHttpApplication.cs’.

I have installed Ninject and Ninject.MVC3 from Nuget. It looks although it is trying to find the files to debug. Would anyone be able to give me any information to why this is happening.

I also receive this error

[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.Single(IEnumerable1 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:08:24+00:00Added an answer on May 21, 2026 at 10:08 am

    Action filters should be registered using the following syntax:

    public override void Load()
    {
        BindFilter<CustomAdminAuthorizationFilter>(FilterScope.Controller, 0);
        Bind<IAuthentication>().To<CustomAuthenticationService>();
    }
    

    You can also apply the filter conditionally.

    Remark: can’t see any relation with the NinjectDependencyResolver class you are showing in your question. That’s already built into ninject.mvc3 and you shouldn’t be writing it manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get a UISlider to work. I'm trying to set the
Currently I'm trying to erase a sequence of iterators from a set, however GCC's
I'm currently trying to query and set some windows registry entries through a Java
I am trying to set the current line number to a variable in Elisp
I'm trying to balance a set of currency values using vb.net. The totals for
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to read in an XML file, make some minor changes (alter
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to build a personal website to create a presence on the
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.