温莎城堡下不中信任工作 [英] Castle Windsor does not work under Medium Trust

查看:160
本文介绍了温莎城堡下不中信任工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图运行它使用温莎城堡ASP.NET MVC应用程序时,会出现以下错误。

When attempting to run an ASP.NET MVC application which uses Castle Windsor, the following error occurs.

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

Server Error in '/' Application.

继承安全规则而重写成员违反了:
  Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()。
  压倒一切的方法的安全辅助功能必须匹配
  该方法的安全辅助功能被覆盖。

Inheritance security rules violated while overriding member: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

说明:在执行过程中发生未处理的异常
  当前Web请求。有关详情,请堆栈跟踪
  有关错误的信息以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.TypeLoadException:继承安全
  规则而重写成员违反了:
  Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()。
  压倒一切的方法的安全辅助功能必须匹配
  该方法的安全辅助功能被覆盖。

Exception Details: System.TypeLoadException: Inheritance security rules violated while overriding member: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

源错误:

的执行过程中生成了未处理的异常
  当前Web请求。有关的起源和位置信息
  除了可以使用异常堆栈跟踪下面来识别。

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

堆栈跟踪:

[TypeLoadException:继承安全规则违反而
  重写成员:
  Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()。
  压倒一切的方法的安全辅助功能必须匹配
  该方法的安全辅助功能被覆盖。]结果
  Castle.Windsor.WindsorContainer..ctor()+ 0

[TypeLoadException: Inheritance security rules violated while overriding member: 'Castle.MicroKernel.DefaultKernel.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.]
Castle.Windsor.WindsorContainer..ctor() +0

大会 Castle.Core.dll Castle.Windsor.dll 已建成了源code在 github上使用。该人士$ ​​C $ C的组件包括文件 SecurityAssemblyInfo.cs 它具有以下源$ C ​​$ C:

The assemblies Castle.Core.dll and Castle.Windsor.dll have been built off the source code available on github. The source code for the assemblies includes the file SecurityAssemblyInfo.cs which has the following source code:

// Sets up assembly level security settings
#if ! SILVERLIGHT
[assembly: System.Security.AllowPartiallyTrustedCallers]
#if DOTNET40
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level2)]
#endif
#endif

我一直在使用 ILSpy 验证了 System.Security.AllowPartiallyTrustedCallers 属性在两个文件大会宣布。

I have verified using ILSpy that the System.Security.AllowPartiallyTrustedCallers attribute is declared at the assembly on both files.

Web应用程序正在运行与<信任级别=中/方式>

The web application is being run with <trust level="Medium" />.

推荐答案

我已经能够通过以下更改获得成功生成+运行我的MVC应用程序的 Castle.Core

I have been able to get a successful build + run of my mvc application by making the following changes to Castle.Core:

更改为的以下内容:

[汇编:System.Security.AllowPartiallyTrustedCallers]
  [大会:System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

[assembly: System.Security.AllowPartiallyTrustedCallers] [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

改三线ProxyGenerator :: ProxyGenerator(IProxyBuilder):

ProxyGenerator.cs:

Changed three lines in ProxyGenerator::ProxyGenerator(IProxyBuilder):

if (HasSecurityPermission())
{
    Logger = new TraceLogger("Castle.DynamicProxy", LoggerLevel.Warn);
}

变成了:

// if (HasSecurityPermission())
// {
//    Logger = new TraceLogger("Castle.DynamicProxy", LoggerLevel.Warn);
// }

我的没有这些想法可能有什么样的后果。这将是很好,如果有人熟悉SecurityRuleSets可以帮腔的第一部分,@KrzysztofKoźmic能告诉我为什么我不得不注释掉跟踪记录。

I have no idea what sort of consequences these might have. It would be nice if someone familiar with the SecurityRuleSets could chime in on the first part, and @Krzysztof Koźmic could advise me on why I had to comment out the trace logger.

这篇关于温莎城堡下不中信任工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆