PersonalDataAttribute 有什么用?

Dej*_*jan 4 c# asp.net-core asp.net-core-identity

我只是偶然发现 ASP.NET Core Identity 框架提供了PersonalData 属性。文档只是说:

用于表示某物被视为个人数据。

好的。这是什么意思?它对身份框架的工作方式或作用有什么影响吗?或者它纯粹是装饰性的,以便我可以对某些对象进行一些反思并记录我的代码?

Kir*_*kin 8

ASP.NET Core 标识 UI 包括一个“下载个人数据”页面,该页面使用该[PersonalData]属性来帮助确定要在下载中包含的内容():

// Only include personal data for download
var personalData = new Dictionary<string, string>();
var personalDataProps = typeof(TUser).GetProperties().Where(
    prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));

foreach (var p in personalDataProps)
{
    personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
}
Run Code Online (Sandbox Code Playgroud)

还有[ProtectedPersonalData],它继承自[PersonalData]。此属性还将 Identity 的 EF Core 集成配置为在属性存储在数据库中时对其进行加密。