aspnet-dataprotection-db

Persist ASP.NET Core DataProtection keys to a relational database via EF Core.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/ecnepsyroc-bot/Dejavara --skill aspnet-dataprotection-db
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: aspnet-dataprotection-db
Source: https://github.com/ecnepsyroc-bot/Dejavara/tree/main/deploy/skills/aspnet-dataprotection-db
Command: npx skills add https://github.com/ecnepsyroc-bot/Dejavara --skill aspnet-dataprotection-db

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

ASP.NET Core DataProtection keys are stored on the filesystem by default and are regenerated after deploys on ephemeral hosts, which invalidates encrypted cookies and tokens and forces users to reauthenticate.

Core Features & Use Cases

  • Database-backed key storage: Persist DataProtection keys to a relational database (PostgreSQL or SQL Server) using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.
  • DbContext integration: Implement IDataProtectionKeyContext on your AppDbContext to host the DataProtectionKeys DbSet and let EF Core persist keys to a data_protection_keys table.
  • Deployment reliability: Prevent session and cookie invalidation on ephemeral platforms like Railway, Heroku, Azure App Service, and containerized deployments.
  • Compatibility guidance: Align EF Core and DataProtection.EntityFrameworkCore package versions and run EF migrations to create the required table.

Quick Start

Add the Microsoft.AspNetCore.DataProtection.EntityFrameworkCore package, implement IDataProtectionKeyContext on your AppDbContext, register AddDataProtection().PersistKeysToDbContext<AppDbContext>() in Program.cs, and run an EF Core migration to update the database.

Frequently Asked Questions about aspnet-dataprotection-db

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do ASP.NET Core authentication cookies invalidate after deploying to ephemeral filesystems?

ASP.NET Core authentication cookies invalidate after deploys because default DataProtection keys are stored on the filesystem. Ephemeral platforms like Railway and Docker lose these keys on restart, invalidating encrypted cookies and forcing users to reauthenticate.

How do I persist ASP.NET Core DataProtection keys to a database using EF Core?

To persist DataProtection keys to a database, add the Microsoft.AspNetCore.DataProtection.EntityFrameworkCore package, implement IDataProtectionKeyContext on your AppDbContext, register PersistKeysToDbContext in Program.cs, and run an EF Core migration to create the data_protection_keys table.

Does ASP.NET Core DataProtection EF Core storage work with PostgreSQL and Docker deployments?

Yes, ASP.NET Core DataProtection EF Core database storage works with PostgreSQL and Docker deployments. It persists keys to a relational database, preventing session invalidation on ephemeral platforms where filesystem keys are lost on restart.

What's the best way to prevent session invalidation on Heroku or Azure App Service for ASP.NET Core?

The best way to prevent session invalidation on Heroku or Azure App Service is database-backed key storage. Persisting ASP.NET Core DataProtection keys to a relational database via EF Core ensures encrypted cookies remain valid across restarts.

Do I need to match EF Core and DataProtection.EntityFrameworkCore package versions for database key persistence?

Yes, you need to match EF Core and DataProtection.EntityFrameworkCore package versions for database key persistence. Aligning versions ensures compatibility when implementing IDataProtectionKeyContext and running migrations to create the data_protection_keys table.