Run templates in sandbox with minimal trust

May 14, 2012 at 12:31 PM


I am trying to run razor templates in sanbox with minimal trust, so it will be more secure in code execution.

I'm getting an System.Security.SecurityException: Request failed, on System.Activator.CreateInstance during construction of IsolatedTemplateService..ctor even I am specifying the RazorEngine as full trust assembly.

the code:
(base on

Service = new IsolatedTemplateService(() => {               
Evidence ev = new Evidence();               
ev.AddHostEvidence(new Zone(SecurityZone.Internet));               
PermissionSet internetPS = SecurityManager.GetStandardSandbox(ev);               
StrongName fullTrustAssembly = typeof(TemplateService).Assembly.Evidence.GetHostEvidence<StrongName>();               
return AppDomain.CreateDomain("RazorHost", null, AppDomain.CurrentDomain.SetupInformation, internetPS, fullTrustAssembly);           

The RazorEngine version is: