However, that will not be enough if you want to implement machine resource-specific restrictions (memory and CPU). An arguably simple way to run your code in a restricted AppDomain AND to limit machine resources consumption would be to use the Managed AddIn framework, and particularly its AddInProccess class (see Managing Add-Ins: Advanced Versioning and Reliable Hosting, Machine Resource Exhaustions section).
发布评论
评论(1)
换句话说,您需要对脚本的执行进行沙箱。
有一种本机 .NET 机制允许您执行此操作:AppDomain 权限。
查看如何:在沙箱中运行部分受信任的代码
但是,如果您想要实施特定于机器资源的限制(内存和 CPU),这还不够。在受限 AppDomain 中运行代码并限制计算机资源消耗的一种可以说是简单的方法是使用 托管 AddIn 框架,特别是其
AddInProccess
类(请参阅管理加载项:高级版本控制和可靠托管、机器资源耗尽< /strong> 部分)。In other words, you need to sandbox the execution of your script.
There is a native .NET mechanism which allows you to do that: AppDomain permissions.
Have a look at How to: Run Partially Trusted Code in a Sandbox
However, that will not be enough if you want to implement machine resource-specific restrictions (memory and CPU). An arguably simple way to run your code in a restricted AppDomain AND to limit machine resources consumption would be to use the Managed AddIn framework, and particularly its
AddInProccess
class (see Managing Add-Ins: Advanced Versioning and Reliable Hosting, Machine Resource Exhaustions section).