c# - 什么是 HostProtectionAttribute,我们为什么要使用它?

标签 c# clr msdn

我想详细了解 C# 中的 HostProtectionAttribute。当然,我阅读了 MSDN 文档 thisthis但我不明白我们为什么要使用它。在文档中有诸如“主机编程模型”之类的术语,这让我对这个主题更加困惑。

假设我们有一个方法有这个属性,如果我删除它会发生什么?

最佳答案

如下文所述;

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/

相关文章:

c# - 从 IEnumerable 中进行选择时避免重复自己

c# - 为什么我不能将 long 的 object-var 转换为 double?

excel - Excel中空点的移动平均计算

c++ - 如何阅读 MSDN 并申请?

c# - MVC应用架构的数据流

c# - DispatcherTimer 使用 MVVM 更新 TextBlock

.net - Windows 服务在启动期间挂起

.net - 如何通过名称获取 AppDomain?

asp.net - 在 SQL Server 2012 中创建 .NET Framework v.2.0 程序集

c++ - "Console::"不编译