I'm developing an ASP.NET MVC application with NHibernate and I'm trying to use Automapper to hide the Domain objects from the DTO objects sent to the view:
我正在使用NHibernate开发一个ASP.NET MVC应用程序,我正在尝试使用Automapper从发送到视图的DTO对象中隐藏Domain对象:
- ClassLibrary with my Domain (for NHibernate) and DTO objects
- ClassLibrary与我的域(用于NHibernate)和DTO对象
- Class library to make a
SessionFactory
and Factories in my Project - 用于在我的项目中创建SessionFactory和Factories的类库
I downloaded AutoMapper to transform Domain objects in DTO and added the code to do this in Application_Start
.
我下载了AutoMapper来转换DTO中的Domain对象,并添加了在Application_Start中执行此操作的代码。
When I run the app in VisualStudio (by pressing F5) it works fine and my DTOs are mapped into the view.
当我在VisualStudio中运行应用程序时(通过按F5),它工作正常,我的DTO映射到视图中。
When I publish this in IIS, I get a security exception:
当我在IIS中发布它时,我得到一个安全异常:
Mapper.CreateMap<Category, CategoryDto>();
Mapper.CreateMap<Product, ProductDto>();
System.Security.SecurityException: Failed request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
System.Security.SecurityException:对类型'System.Security.Permissions.ReflectionPermission,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限的请求失败。
How do I get Automapper to work without the security exception?
如何在没有安全性异常的情况下使Automapper工作?
3 个解决方案
#1
3
you need to run your IIS in full trust in order to have reflection permission, look here reflection permission
您需要完全信任地运行IIS才能获得反射权限,请查看此处的反射权限
or here set trust level
或者在这里设置信任级别
you need this because Automapper uses reflection to emit code o_O
#2
13
Right click on the AutoMapper.dll > select properties > Unblock.
右键单击AutoMapper.dll>选择属性>取消阻止。
Then restart IIS
然后重启IIS
#3
0
Unblock the dll (as mentioned by Lee, Right click on the AutoMapper.dll > select properties > Unblock.), and then just recycle the site's app pool. Need not restart IIS.
取消阻止dll(如Lee所述,右键单击AutoMapper.dll>选择属性>取消阻止。),然后只回收站点的应用程序池。无需重启IIS。
#1
3
you need to run your IIS in full trust in order to have reflection permission, look here reflection permission
您需要完全信任地运行IIS才能获得反射权限,请查看此处的反射权限
or here set trust level
或者在这里设置信任级别
you need this because Automapper uses reflection to emit code o_O
#2
13
Right click on the AutoMapper.dll > select properties > Unblock.
右键单击AutoMapper.dll>选择属性>取消阻止。
Then restart IIS
然后重启IIS
#3
0
Unblock the dll (as mentioned by Lee, Right click on the AutoMapper.dll > select properties > Unblock.), and then just recycle the site's app pool. Need not restart IIS.
取消阻止dll(如Lee所述,右键单击AutoMapper.dll>选择属性>取消阻止。),然后只回收站点的应用程序池。无需重启IIS。