對於我目前的項目,我使用Dapper。一切都很完美。然後我需要將它部署在共享主機上。結果可以在這裡看到(複製YSOD):
說明:應用程序嘗試執行安全策略不允許的操作。要授予此應用程序所需的權限,請與系統管理員聯繫或在配置文件中更改應用程序的信任級別。
異常詳細信息:System.Security.SecurityException:請求類型'System.Security.Permissions.ReflectionPermission,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的權限失敗。
堆棧跟踪
[SecurityException:請求類型'System.Security.Permissions.ReflectionPermission,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的權限失敗。] System.Security.CodeAccessSecurityEngine.Check(Object demand,StackCrawlMark&stackMark ,Boolean isPermSet)+0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission上限,StackCrawlMark和stackMark)+31
System.Security.CodeAccessPermission.Demand()+46
System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner,StackCrawlMark&stackMark,Boolean skipVisibility)+9461551
System.Reflection.Emit.DynamicMethod..ctor(String name,Type returnType,Type [] parameterTypes,Type owner,Boolean skipVisibility)+40 Dapperx.SqlMapper.CreateParamInfoGenerator(Identity identity)+537 Dapperx.SqlMapper.GetCacheInfo(Identity identity) +376 Dapperx.d__131.MoveNext() +644
1..ctor(IEnumerable
System.Collections.Generic.List1 collection) +327 System.Linq.Enumerable.ToList(IEnumerable
1 source)+58
Dapperx.SqlMapper.Query(IDbConnection cnn,String sql,Object param,IDbTransaction事務,Boolean buffered,Nullable1 commandTimeout, Nullable
1 commandType)+199
...
有沒有辦法解決它(在.NET 4.0中)?據我所知,到目前為止我所閱讀的內容,提供商必須允許一些部分來反映IIS,這可能會對他們造成安全風險......
在Medium Trust中不允許使用Dapper使用的Reflection.Emit。
您應該找到提供完全信任的託管服務提供商。 discountasp.net是我以前用過的。