简体   繁体   English

从ASP.NET框架功能限制C#代码

[英]Restrict C# code from ASP.NET framework features

Is it possible to restrict code access for certain .NET functionality/classes? 是否可以限制某些.NET功能/类的代码访问?

For example, I have plugin modules for my MVC CMS. 例如,我有用于MVC CMS的插件模块。 I wouldn't want 3rd party modules able to use the File class directly. 我不希望第3方模块能够直接使用File类。 I would want to wrap it up in an API so that the module can only access files in it's own designated 'root' folder (sandbox). 我想将其包装在API中,以便该模块只能访问其自己指定的“根”文件夹(沙盒)中的文件。 Otherwise, the module would have file access to the entire server, including the CMS system files. 否则,该模块将具有对整个服务器(包括CMS系统文件)的文件访问权限。

Is there a way to restrict certain namespaces from using particular features of the framework? 有没有一种方法可以限制某些名称空间使用框架的特定功能? Or is there a different approach that I should take? 还是我应该采取其他方法?

To give you an overview: 给您一个概述:

The CMS namespace is MyCms CMS命名空间是MyCms

All modules take the namespace MyCms.Module.xxxxx 所有模块都使用命名空间MyCms.Module.xxxxx

Modules are just standard MVC structures that are brought into the name main MVC namespace, and routes are automatically set up to route requests to the module controllers. 模块只是带入名称MVC名称空间中的标准MVC结构,并且会自动设置路由以将请求路由到模块控制器。

Therefore the modules have default access to the ASP.NET framework. 因此,这些模块具有对ASP.NET框架的默认访问权限。 I want to be able to restrict MyCms.Module.xxxxx namespaces from being able to do certain things, if that is possible. 我希望能够限制MyCms.Module.xxxxx命名空间执行某些操作(如果可能)。

Have I taken the wrong approach here? 我在这里采取了错误的方法吗? I'm not keen to change the infrastructure to be honest, but may be forced to if I can't properly secure the main CMS infrastructure from naughty modules. 老实说,我不希望改变基础架构,但是如果我不能从顽皮的模块中适当地保护主要CMS基础架构,可能会被迫采取措施。

Are you going give your 3rd party source code or Just a compiled API dll? 您要提供第三方的源代码还是只是编译的API dll? if it's later, then a setting up a interface and only exposing methods you want your 3rd party to use, sounds like a answer to me. 如果是后来的话,那么设置一个界面并仅公开您希望您的第三方使用的方法,听起来像是对我的回答。 of course, it is also heavily relied on the architect of your codebase. 当然,它也非常依赖于代码库的架构师。

or simply providing your 3rd party a specified document would do the trick as well 或者只是向您的第三方提供指定的文档也可以解决问题

Yeah, the .net/ the common language runtime supports a wide set of privilege restrictions and customizations you can put in for what code can do what. 是的,.net /公共语言运行库支持各种权限限制和自定义设置,您可以针对这些代码执行的操作进行设置。

This is an overview of how it worked prior to .net 4 是它在.net 4之前的工作方式的概述。

http://msdn.microsoft.com/en-us/library/.aspx http://msdn.microsoft.com/en-us/library/.aspx

This is how it works now 是如何工作的,现在

This stuff is a little complicated and my work with it was limited to bipassing some of it for test cases I had to write, but it was written to provide precisely the functionality you seek. 这些东西有些复杂,我的工作仅限于将其用于我必须编写的测试用例中,但它的编写恰恰是为了提供您想要的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM