【问题标题】:Security exception with Nhibernate on shared hostingNhibernate 在共享主机上的安全异常
【发布时间】:2011-09-04 19:39:35
【问题描述】:

我有一个使用 nhibernate 的网站,它托管在共享网络主机上。

我已经通过“NHibernate.Cfg.Environment.UseReflectionOptimizer = false;”禁用了延迟加载因为我的主机不允许反射。

但是现在我在使用 nhibernate 时遇到了另一个问题:

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request failed.

Source Error:

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.

Stack Trace:

[SecurityException: Request failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +168
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +278
   System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandleInternal rmh) +69
   System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandleInternal rmh) +156
   System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +33
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +128
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +54

每次使用 nhibernate 时都会发生此错误(用于数据库访问)。我已将 Nhibernate 降级为 1.2,现在仅针对在映射文件中声明了关系的对象的更新和删除操作引发异常。

我认为错误是由 Castle.DynamicProxy.dll 引起的。但是如何完全禁用代理?我已经在lazy="false" 上设置了映射中的所有对象和关系,我已经设置了default-lazy="false"

在 nhibernate 助手中我也设置了 NHibernate.Cfg.Environment.BytecodeProvider = null; 但这没有帮助。

这是一个详细说明我的主机http://onlinehelp.hostbasket.com/shared-webhosting/scripting/asp-aspnet/1147-why-does-hostbasket-not-support-my-site-in-full-trust.html的信任设置的网址

【问题讨论】:

  • 您根本无法禁用代理。这就是 NHibernate 的工作原理。
  • 我想我确实禁用了代理。我已经删除了用于代理的 dll,该网站仍然可以在我的本地开发机器上运行。但是在网上它又给了我一个安全例外:(。如果我不能解决这个问题,我将不得不使用 OleDb 进行更新和删除操作。

标签: asp.net nhibernate proxy shared-hosting securityexception


【解决方案1】:

如果您尝试以中等信任度设置环境(因为您使用的是共享提供商),请查看这个现有的 SO 答案:

"Security" problem with NHibernate on deployed web application

具体来说,NHibernate 的 Wiki 链接:http://nhforge.org/wikis/howtonh/run-in-medium-trust.aspx

【讨论】:

  • 我已经做了这些事情,但没有帮助,问题是网络主机使用的不是中等信任,而是自定义信任。我已经在谷歌上搜索了大约三天的答案,我尝试了我在网上可以找到的所有内容,没有任何帮助
  • 是的,重新阅读主机的政策。在构建时而不是运行时生成代理呢?如果我记得(我对 ProxyGenerators 的工作不多),它会找到编译后的版本,并且不会尝试在运行时生成它们。更多信息:sourceforge.net/projects/nhcontrib/files/…
猜你喜欢
  • 1970-01-01
  • 2013-01-15
  • 1970-01-01
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多