0

我试图让我的 Web 应用程序用 ASP.NET 4.0 编写,使用中等信任在本地工作。我使用 Go Daddy 作为网络主机,他们在共享主机上使用中等信任。我已经读到 nHibernate 现在可以在 3.3 中开箱即用地与 Medium Trust 站点一起使用,但我无法终生工作。

只需添加:

<trust level="Medium" />

在我的 web.config 中,我的 Web 应用程序因以下错误和堆栈跟踪而崩溃:

Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
   at System.Security.CodeAccessPermission.Demand()
   at System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner, StackCrawlMark& stackMark, Boolean skipVisibility)
   at System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility)
   at NHibernate.Bytecode.Lightweight.ReflectionOptimizer.CreateDynamicMethod(Type returnType, Type[] argumentTypes)
   at NHibernate.Bytecode.Lightweight.ReflectionOptimizer.GenerateGetPropertyValuesMethod(IGetter[] getters)
   at NHibernate.Bytecode.Lightweight.ReflectionOptimizer..ctor(Type mappedType, IGetter[] getters, ISetter[] setters)
   at NHibernate.Bytecode.Lightweight.BytecodeProviderImpl.GetReflectionOptimizer(Type mappedClass, IGetter[] getters, ISetter[] setters)
   at NHibernate.Tuple.Entity.PocoEntityTuplizer.SetReflectionOptimizer()
   at NHibernate.Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappedEntity)
   at NHibernate.Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass mappedEntity, EntityMetamodel em)
   at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory)
   at NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
   at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping)
   at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg)
   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   at NHibernate.DataAccess.WebTest.Code.NHibernateHelper.get_SessionFactory()
   at NHibernate.DataAccess.WebTest.Code.NHibernateHelper.OpenSession()
   at NHibernate.DataAccess.WebTest._Default.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

这似乎与我读到的错误相同,但到目前为止我发现的所有修复程序似乎都没有对我有用。我什至尝试过 NHibernate.DependencyInjection Nuget 包,但出现相同错误但堆栈跟踪不同的错误,这发生在 Initializer ctor 中。

我觉得我错过了一些明显的东西来完成这项工作,但我不能指望它。有没有人在中等信任下运行 nHibernate 3.3.1 有任何成功?

4

2 回答 2

2

我可以通过关闭 ado 批处理来完成这项工作。我在这里找到了答案,http://blog.ondrejsv.com/post/N2CMS-NHibernate-SqlCommandSet-and-medium-trust.aspx。警告,我还没有将它迁移到生产环境;这只是在我的笔记本电脑上(YMMV)。

<property name="adonet.batch_size">0</property>

我尝试了 NHibernate.DependencyInjection 包,但它没有用。

希望这可以帮助。

于 2012-10-02T19:59:35.070 回答
1

我与我的中等信任提供商一起使用开箱即用的 NH 3.3.1。但是,可能还有其他东西可以帮助您。Ranzlee安装此软件包:-

PM> Install-Package NHibernate.DependencyInjection

要启动并运行它,只需使用

protected void Application_Start() {
  Initializer.RegisterBytecodeProvider();
  ...
  Rest of configuration code here
}
于 2012-08-25T17:30:22.887 回答