Asp.net mvc 3 使用Ninject';时,相同类型的多个属性失败;Binds过滤器<;T>;

Asp.net mvc 3 使用Ninject';时,相同类型的多个属性失败;Binds过滤器<;T>;,asp.net-mvc-3,authorization,ninject,Asp.net Mvc 3,Authorization,Ninject,作为启用身份的授权系统的一部分,我希望使用IAUhorizationFilter和属性来限制对控制器中操作方法的访问。我的工作非常顺利,部分原因是来自以下资源的帮助: 但是,当我尝试用我的多个属性装饰一个动作方法时,我会遇到如下异常(很抱歉格式化): 过滤器: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] public class SampleAttri

作为启用身份的授权系统的一部分,我希望使用IAUhorizationFilter和属性来限制对控制器中操作方法的访问。我的工作非常顺利,部分原因是来自以下资源的帮助:

但是,当我尝试用我的多个属性装饰一个动作方法时,我会遇到如下异常(很抱歉格式化):

过滤器:

[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;
        }
    }
}
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");
        }
    }
public class HomeController : Controller
    {
        [Sample(true)]
        [Sample(false)]
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }
    }
控制器:

[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;
        }
    }
}
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");
        }
    }
public class HomeController : Controller
    {
        [Sample(true)]
        [Sample(false)]
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }
    }
如果删除
Index()
方法上的
Sample
属性中的一个或另一个,则上述控制器方法将正常工作。将两者都放在适当的位置,将生成异常。我意识到在这个简化的例子中,没有一种情况需要两个属性,但这只是为了说明


我遗漏了什么?

这是Ninject 2.2的一个已知问题。请改用3.0


这是Ninject 2.2的已知版本。请改用3.0


谢谢你,雷莫。我很感激你提供的信息,你回复这里帖子的速度之快给我留下了深刻的印象。谢谢。NuGet的3.0.0-rc3仍然存在同样的问题。我按照上面相同的概念创建了一个新的示例项目,得到了InvalidOperationException:“Sequence包含多个元素”。有什么想法吗?谢谢,雷莫。我很感激你提供的信息,你回复这里帖子的速度之快给我留下了深刻的印象。谢谢。NuGet的3.0.0-rc3仍然存在同样的问题。我按照上面相同的概念创建了一个新的示例项目,得到了InvalidOperationException:“Sequence包含多个元素”。有什么想法吗?