Deploy self-contained trimmed builds for smaller binaries. Example for build optimization: dotnet publish -c Release /p:PublishTrimmed=true /p:ReadyToRun=true 🔐 10. What is Data Protection in ASP.NET Core? Follow :
ASP.NET Core Data Protection API provides secure cryptographic APIs for:
- Encrypting cookies and tokens
- Protecting form data
- Persisting secure keys (across app restarts)
Setup:
builder.Services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"c:\keys"))
.SetApplicationName("MyApp");
You can use it directly:
var protector = _provider.CreateProtector("MyPurpose");
var encrypted = protector.Protect("secret-data");
var decrypted = protector.Unprotect(encrypted);
✅ Data Protection is the backbone for:
- Cookie Authentication
- CSRF Tokens
- TempData encryption
🧠 Summary
Concept Description Best For
In-memory caching Stores data in server memory Single-server or dev
Distributed caching Shared cache (Redis, SQL) Scalable apps
Response caching Caches HTTP responses Public/static data
Follow :
Output caching (.NET 8) Advanced, user-aware
caching
Dynamic APIs
Response compression Gzip/Brotli for responses Large payloads
Async/await Non-blocking I/O High concurrency
Startup optimization Faster app boot Cloud apps
Data protection Encrypt sensitive data Cookies, tokens,
forms
Testing
How to Unit Test Controllers?
Unit testing controllers ensures your business logic in action methods works correctly
without hitting the database or HTTP pipeline.
Steps: