Security exception with Nhibernate on shared hosting
I have a website which uses nhibernate, it is hosted on a shared web host.
I already disabled lazy loading trough "NHibernate.Cfg.Environment.UseReflectionOptimizer = false;" because reflection isn't allowed on my host.
But now I have another problem with 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, RuntimeMethodHandle开发者_Python百科Internal 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
This error occurred everytime nhibernate was used(for database access). I've downgraded Nhibernate to 1.2 and now the exception only is thrown for update and delete operations of objects which have relations declared in the mapping file.
I think the error is caused by Castle.DynamicProxy.dll. But how do I disable proxies completely? I have set all objects and relations in the mapping on lazy="false"
, I've set default-lazy="false"
in the nhibernate helper I also have set NHibernate.Cfg.Environment.BytecodeProvider = null;
but this doesn't help.
here is a url detailing the trust settings of my host http://onlinehelp.hostbasket.com/shared-webhosting/scripting/asp-aspnet/1147-why-does-hostbasket-not-support-my-site-in-full-trust.html
If you're attempting to set up the environment in medium trust (since you're on a shared provider), check out this existing SO answer:
"Security" problem with NHibernate on deployed web application
Specifically, the link to NHibernate's Wiki: http://nhforge.org/wikis/howtonh/run-in-medium-trust.aspx
精彩评论