限制 MS 脚本引擎中命名空间的使用
.NET Framework 具有支持在运行时编译代码并运行它的强大功能,以实现某些类型的脚本功能。 CodeProject 上已经有一些可用的脚本引擎,微软也有自己的库。
我正在开发一个网络自动化软件,我想在应用程序中包含 Microsoft 脚本引擎。
问题是脚本引擎允许在引用的程序集中使用所有命名空间,而我想将使用限制为选定的几个命名空间。
using System; // allowed.
using System.Linq; // allowed.
using System.Reflection; // restrict.
如何在脚本中限制命名空间的使用。
The .NET Framework has great features to support compiling code at runtime and running it, to achieve some kinds of scripting functionalities. There are already some scripting engines available on CodeProject, and Microsoft has its own library as well.
I am working on a web automation software, I want to include the Microsoft scripting engine in the application.
The problem is the scripting engines allow Using all namespace, in the referenced assembly, and I want to restrict the usage to a selected few namespace.
using System; // allowed.
using System.Linq; // allowed.
using System.Reflection; // restrict.
How to restrict the use of namespaces, in the scripts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按名称限制命名空间并不能起到多大作用,因为扩展只能在其自己的程序集中包含您不喜欢的类的副本,但只是重命名。
听起来您真正想要的是安全边界。将扩展放入不受信任的 AppDomain 中。
Restricting namespaces by name doesn't accomplish much since the extension can just include a copy of the class you don't like in its own assembly, but just renamed.
It sounds like what you really want is a security boundary. Put the extension in an untrusted AppDomain.