Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the PersonalDataAttribute good for?

I just stumbled over the fact that ASP.NET Core Identity framework offers a PersonalData attribute. The docs merely say:

Used to indicate that a something is considered personal data.

Okay. What does it mean? Does it have any implication on how the identity frameworks works or what it does? Or is it purely decorative, so that I can do some reflection on some objects and document my code?

like image 483
Dejan Avatar asked Oct 29 '20 10:10

Dejan


People also ask

What is IHttpContextAccessor?

ASP.NET Core applications access the HTTPContext through the IHttpContextAccessor interface. The HttpContextAccessor class implements it. You can use this class when you need to access HttpContext inside a service.

What is AddEntityFrameworkStores?

AddEntityFrameworkStores<TContext>(IdentityBuilder)Adds an Entity Framework implementation of identity information stores. C# Copy.

What is scaffold identity?

ASP.NET Core provides ASP.NET Core Identity as a Razor Class Library. Applications that include Identity can apply the scaffolder to selectively add the source code contained in the Identity Razor Class Library (RCL). You might want to generate source code so you can modify the code and change the behavior.


1 Answers

The ASP.NET Core Identity UI includes a "Download Personal Data" page, which uses the [PersonalData] attribute to help determine what to include in the download (source):

// 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");
}

There's also [ProtectedPersonalData], which inherits from [PersonalData]. This attribute also configures Identity's EF Core integration to encrypt the property when it's stored in the database.

like image 82
Kirk Larkin Avatar answered Sep 28 '22 03:09

Kirk Larkin