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 7606619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:27:21+00:00 2026-05-31T00:27:21+00:00

As part of a identity-enabled authorization system, I’d like to use IAuhtorizationFilter and Attributes

  • 0

As part of a identity-enabled authorization system, I’d like to use IAuhtorizationFilter and Attributes to restrict access to action methods in my controllers. I’ve got things working very well, partly due to help from the following resources:

  • Ninject Binding Attribute to Filter with Constructor Arguments
  • https://github.com/ninject/ninject.web.mvc/wiki/Filter-configurations
  • Custom Authorization MVC 3 and Ninject IoC
  • https://github.com/ninject/ninject.web.mvc/wiki/Dependency-injection-for-filters

However, when I try to decorate an action method with more than one of my attributes, I get an exception as follows (sorry for the formatting):

[InvalidOperationException: Sequence contains more than one element]

System.Linq.Enumerable.Single(IEnumerable`1 source) +2691369
   Ninject.Web.Mvc.FilterBindingSyntax.c__DisplayClass15`1.b__14(IContext ctx, ControllerContext controllerContext, ActionDescriptor actionDescriptor) in c:\Projects\Ninject\Maintenance2.2\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\FilterBindingSyntax\FilterFilterBindingBuilder.cs:379
   Ninject.Web.Mvc.FilterBindingSyntax.c__DisplayClass12.b__11(IContext ctx) in c:\Projects\Ninject\Maintenance2.2\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\FilterBindingSyntax\FilterFilterBindingBuilder.cs:358
   Ninject.Parameters.c__DisplayClass6.b__4(IContext ctx, ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Parameters\Parameter.cs:60
   Ninject.Parameters.Parameter.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Parameters\Parameter.cs:88
   Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:97
   Ninject.Activation.Providers.c__DisplayClass2.b__1(ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:81
...

Here is a very simplified version of my code that demonstrates the problem in an MVC3 app:

Attribute:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class SampleAttribute : Attribute
{
    private Guid typeId;

    public bool IsAllowed { get; set; }

    public SampleAttribute(bool IsAllowed)
    {
        this.IsAllowed = IsAllowed;

        this.typeId = new Guid();
    }

    public override object TypeId
    {
        get
        {
            return (object)typeId;
        }
    }
}

Filter:

public class SampleFilter : IAuthorizationFilter, IMvcFilter
    {
        private bool isAllowed;

        public bool AllowMultiple
        {
            get { return true; }
        }

        public int Order
        {
            get { return 0; }
        }

        public SampleFilter(bool isAllowed)
        {
            this.isAllowed = isAllowed;
        }

        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (!isAllowed)
                throw new Exception("unauthorized");
        }
    }

Controller:

public class HomeController : Controller
    {
        [Sample(true)]
        [Sample(false)]
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }
    }

The controller method above works as expected if one or the other of the Sample attributes on the Index() method is removed. Having both in place, generates the exception. I realize that in this simplified example, there isn’t a situation that would call for both attributes, but it’s simply for illustration.

What am I missing?

  • 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-31T00:27:22+00:00Added an answer on May 31, 2026 at 12:27 am

    This is a known issue of Ninject 2.2. Please use 3.0 instead.

    https://github.com/ninject/ninject.web.mvc/blob/master/mvc3/ReleaseNotes.txt

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

Sidebar

Related Questions

Part of my code goes like this: while(1){ my $winmm = new Win32::MediaPlayer; $winmm->load('1.mp3');
Through the AWS Identity and Access Management, I have a user account to the
The identity map and unit of work patterns are part of the reasons sqlalchemy
I have a HashSet of Identity values that I need to use as the
I just inherited a stored procedure as part of a system for inserting a
I have a table like these: Club Table contains: ClubID(IDENTITY), Name, Address Genre table
Part of the GUI I'm building using tkinter has a pop-up window that says
Part of my web application is a background script that polls from a beanstalkd
Part of our website is protected with .htaccess style password protection. When you try
Part of my app caches web pages for offline viewing. To do that, I

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.