c# - 如何在 .NET sdk 5 上实现 SecurityPermission?
问题描述
在以前版本的 .NET sdk 中,我们实现了以下代码:
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
protected HttpResponseException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
ErrorId = (Guid)info.GetValue("ErrorId", typeof(Guid));
StatusCode = (HttpStatusCode)info.GetValue("StatusCode", typeof(HttpStatusCode));
ShouldLog = info.GetBoolean("ShouldLog");
}
我已经迁移到 .NET 5,我们已经开始面临很多关于它的警告:
SecurityPermissionAttribute is deprecated: Code Access Security is not supported or honored by the runtime
迁移它的正确方法是什么?只是删除注释或抑制警告消息?
解决方案
代码访问安全 (CAS) API在 .NET Core 到 .NET 5 的所有版本中都不起作用
。
换句话说:它们……什么都没有。
这些类型是从 .NET Framework 4 继承的,以便更轻松地迁移代码,仅此而已 - 只是为了避免编译错误。在某些情况下,您甚至可能会得到一个PlatformNotSupportedException
.
您现在可以将其全部保留,但由于它什么都不做,它只有一个目的:提醒您 (a) 您应该考虑将其删除,同时 (b) 评估放入它的原因 + 替换什么您可能想要添加的保护措施,以获得类似于它在 .NET Framework 中为您提供的保护措施。
推荐阅读
- android - Android Studio - 更改选定的cardview背景颜色变化不止一种
- json - 如何使用 react js 映射它?
- html-email - 为什么文本链接更大?
- reactjs - GlobalStyle 中的背景图像在 React App 中加载了几次
- dart - 如何使用 dart 创建 ArrayAddition 函数
- flutter - _formKey.currentState.validate() 上的 Flutter/Dart Null 安全性?
- javascript - 类型错误:tf.shape 不是函数
- django - Django如何从QueryDict更新模型字段
- javascript - How to show filtered data in Javascript callback function react-calendar-month-view?
- javascript - Auth0: Is there a way to switch accounts?