Restrict access to .NET assembly?

依然范特西╮ 提交于 2019-12-30 01:23:04

问题


Is there a way to have a .NET assembly accessible for only authorized sources?

I mean I want to have a DLL that contains components, but I don't want anyone to be able to use these components but the other DLLs EXEs in my solution. I do want them to be in separated DLLs though.

Restriction on namespace might also be a good idea if this feature exists out there.

Is there a way?


回答1:


You can create internal classes. And the give your specified assemblies to access these classes by using InternalsVisibleTo attribute.

The assembly should be strong named. You can find more information about the attribute in this article.




回答2:


The problem with Internal classes is Internal has no meaning in IL and the classes can be called via reflection. So using InternalsVisibleTo is more a helper for the compiler than anything else.

You can go one step further using the StrongNameIdentityPermission which will check the public key of the strong named assembly calling into the code - if the public key doesn't match then a security exception is thrown. This is enforced even when code is called via reflection.



来源:https://stackoverflow.com/questions/1416190/restrict-access-to-net-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!