Ninject.MVC3 + MediumTrust =安全例外

时间:2012-02-14 15:39:09

标签: ninject bootstrapper asp.net-mvc-4

  1. 我创建了一个类型为Asp.net MVC 4
  2. 的新项目
  3. 我通过Ninject.MVC3 NuGet Install Package Ninject.MVC3
  4. 安装了软件包
  5. 运行项目时出现安全错误:
  6. 错误

      '/ MediumTrustSample'应用程序中的服务器错误。

         

    安全例外

         

    描述:应用程序尝试不执行操作   安全政策允许。授予此应用程序   必要的权限请联系您的系统管理员或更改   应用程序在配置文件中的信任级别。

         

    异常详细信息:System.Security.SecurityException:请求   'System.Security.Permissions.ReflectionPermission类型的权限,   mscorlib,版本= 4.0.0.0,文化=中性,   PublicKeyToken = b77a5c561934e089'失败。

         

    来源错误:

         

    第20行:
      DynamicModuleUtility.RegisterModule(typeof运算(OnePerRequestModule));线   21:
      DynamicModuleUtility.RegisterModule(typeof运算(HttpApplicationInitializationModule));   第22行:bootstrapper.Initialize(CreateKernel);第23行:
      第24行:

         

    源文件:C:\ Users \ Riderman_2 \ Documents \ Visual Studio   2010 \项目\ MediumTrustSample \ MediumTrustSample \ App_Start \ NinjectMVC3.cs   行:22

         

    堆栈追踪:

         

    [SecurityException:请求类型的权限   'System.Security.Permissions.ReflectionPermission,mscorlib,   Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'   失败。]
      System.Security.CodeAccessSecurityEngine.SpecialDemand(PermissionType   whatPermission,StackCrawlMark& stackMark)+0
      System.Security.CodeAccessPermission.Demand(PermissionType   permissionType)+30
      System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags   invokeAttr,Binder binder,Object []参数,CultureInfo文化,   布尔值skipVisibilityChecks)+281
      System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags   invokeAttr,Binder binder,Object []参数,CultureInfo文化)   +38 Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition(MethodInfo)   ExtensionsForMemberInfo.cs中的方法,BindingFlags标志:145
      Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined(的PropertyInfo   in,element,TypeType,Boolean inherit)in   ExtensionsForMemberInfo.cs:173个
      Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(的MemberInfo   在StandardInjectionHeuristic.cs中的成员)47   Selector.cs中的Ninject.Selection。&lt;&gt; c_ DisplayClass3.b _2(IInjectionHeuristic h):92 System.Linq.Enumerable.Any(IEnumerable 1 source, Func 2谓词)+149 <登记/>   Ninject.Selection.Selector.b_ 1(的PropertyInfo   p)在Selector.cs中:92
      System.Linq.WhereEnumerableIterator 1.MoveNext() +156
    System.Collections.Generic.List
    1.InsertRange(Int32 index,   IEnumerable的1 collection) +552
    Ninject.Selection.Selector.SelectPropertiesForInjection(Type type) in Selector.cs:89
    Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute(IPlan plan) in PropertyReflectionStrategy.cs:60
    Ninject.Planning.<>c__DisplayClass3.<GetPlan>b__1(IPlanningStrategy s) in Planner.cs:68
    Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable
    1   系列,动作1 action) in ExtensionsForIEnumerableOfT.cs:23
    Ninject.Planning.Planner.GetPlan(Type type) in Planner.cs:70
    Ninject.Activation.Context.Resolve() in Context.cs:180
    Ninject.KernelBase.<Resolve>b__7(IContext context) in KernelBase.cs:375
    System.Linq.WhereSelectEnumerableIterator
    2.MoveNext()+238
      System.Linq.Enumerable.SingleOrDefault(IEnumerable 1 source) +299
    Ninject.Planning.Targets.Target
    1.GetValue(类型服务,IContext   父母)在Target.cs中:179
      Ninject.Planning.Targets.Target 1.ResolveWithin(IContext parent) in Target.cs:147
    Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in StandardProvider.cs:97
    System.Linq.WhereSelectArrayIterator
    2.MoveNext()+110
      System.Linq.Buffer 1..ctor(IEnumerable 1来源)+488
      System.Linq.Enumerable.ToArray(IEnumerable 1 source) +104
    Ninject.Activation.Providers.StandardProvider.Create(IContext context) in StandardProvider.cs:81 Ninject.Activation.Context.Resolve() in Context.cs:157 Ninject.KernelBase.<Resolve>b__7(IContext context) in KernelBase.cs:375
    System.Linq.WhereSelectEnumerableIterator
    2.MoveNext()+238
      System.Linq.d
    _b1 1.MoveNext() +296
    System.Linq.Enumerable.Single(IEnumerable
    1来源)+282
      Ninject.ResolutionExtensions.Get(IResolutionRoot root,IParameter []   参数)在ResolutionExtensions.cs中:37
      Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback)   在Bootstrapper.cs中:72
      MediumTrustSample.App_Start.NinjectMVC3.Start()in   C:\ Users \ Riderman_2 \ Documents \ Visual Studio   2010 \项目\ MediumTrustSample \ MediumTrustSample \ App_Start \ NinjectMVC3.cs:22

         

    版本信息:Microsoft .NET Framework版本:4.0.30319;   ASP.NET版本:4.0.30319.272

    问题

    如何将Ninject.MVC3与MediumTrust一起使用?

1 个答案:

答案 0 :(得分:2)

去获取中等信任版本:https://github.com/ninject/ninject/downloads