我想详细了解 C# 中的 HostProtectionAttribute。当然,我阅读了 MSDN 文档 this和 this但我不明白我们为什么要使用它。在文档中有诸如“主机编程模型”之类的术语,这让我对这个主题更加困惑。
假设我们有一个方法有这个属性,如果我删除它会发生什么?
最佳答案
如下文所述;
Given these attributes, SQL Server specifies a list of HPAs that are disallowed in the hosted environment through code access security (CAS). The CAS requirements are specified by one of three SQL Server permission sets: SAFE, EXTERNAL_ACCESS, or UNSAFE. One of these three security levels is specified when the assembly is registered on the server, using the CREATE ASSEMBLY statement. Code executing within the SAFE or EXTERNAL_ACCESS permission sets must avoid certain types or members that have the System.Security.Permissions.HostProtectionAttribute attribute applied.
The HostProtectionAttribute is not a security permission as much , in that **it identifies specific code constructs, either types or methods, that the host may disallow
I couldn't figure out why we use it.
我们用它来帮助我们在主机环境中编写可预测的代码,因为
it identifies specific code constructs, either types or methods, that the host may disallow
Suppose that we have a method that has this attribute and what happens if I delete it?
当您删除它时,如果该方法包含主机可能不允许的类型或某些代码构造,您将永远不会知道,因此它可能会导致您的代码在主机环境(例如 SQL Server)中出现不可预测的行为.我希望这能让它更有帮助。
关于c# - 什么是 HostProtectionAttribute,我们为什么要使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41357119/