插件示例
我正在创建一个与网络相关的应用程序,我想为其添加插件支持。但我希望插件 dll 受到除 SaveSettings()、RequestPage() 和 SendToHost() 方法之外的一切的限制。有什么好的例子如何做到这一点?
I'm creating a web-related application and I want to add plugin support to it. But I want the plugin dlls to be restricted from everything except my SaveSettings(), RequestPage() and SendToHost() methods. Any good examples how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以要求您的插件实现包含这三个方法的接口。然后,在您的代码中,您将在需要应用插件功能的地方调用这些方法。
当然,这不会阻止他们在那些不需要的方法中执行代码。在这种情况下,这更像是一个安全问题。除了将插件程序集加载到另一个 AppDomain 并在 AppDomain 上设置关于它们可以执行的操作的安全限制之外,我想不出一种简单的方法来执行此操作。当然,这也会使您在插件和代码之间传递数据的方式变得复杂。
You can require your plugins to implement an interface which contains those three methods. In your code then you would call those methods where it is necessary to apply the plugin functionality.
Of course this will not prevent them from executing code within those methods that is not desirable. This becomes more of a security problem in this case. I can't think of a straightforward way of doing this except to load the plugin assemblies into another AppDomain and set security restrictions on the AppDomain about what they can do. This will also of course complicate how you pass data between your plugin and your code.