Examine Up and Down methods
| Product family | ASP.NET Core |
|---|---|
| Document source | Aspnet Core Aspnetcore 10.0 |
| Guide type | Reference Guide |
| Skill level | Intermediate to advanced |
| Time | 15 - 60 minutes depending on environment |
This page documents Examine Up and Down methods for engineers working with ASP.NET Core. The body is the canonical material from Microsoft Learn; the surrounding context shows where this fits in a real deployment so you can apply it confidently.
Hands-on walkthrough
ASP.NET Core 10 packs a lot of small wins. Examine Up and Down methods is one of those features that doesn't make headlines, but quietly removes friction once you start using it. Here's how I think about it on real projects.
I once helped a client in Hyderabad untangle this over a 2-hour Teams call. Their issue traced back to a Group Policy from 2018 nobody had cleaned up.
Setup
- .NET 10 SDK. Check with
dotnet --list-sdks— you want a 10.0.x line. - An ASP.NET Core project. New one:
dotnet new webapi -n MyApi(5 seconds) ordotnet new mvc -n MyMvc. - A working editor and a way to hit your endpoints — I use
curl, Insomnia, or the built-in .http file support in VS Code. - About 20-30 minutes the first time. Less once the pattern is muscle memory.
Walkthrough
- Read the change in context. Open
Program.cs. The most common entry point for ASP.NET Core configuration. If you're on minimal hosting model, it's the only place you'll touch for most setup tasks. - Add the service registration in the service-configuration block. Pattern:
builder.Services.AddXyz(options => { /* options */ }). Place it after framework services but before app build. - Wire the middleware if needed. Order matters in the middleware pipeline. As a rule: routing, then auth, then auth, then endpoints. Anything that needs to see the authenticated user goes after auth.
- Configure via
appsettings.json. Convention-based. Keep secrets in User Secrets (dotnet user-secrets set "MyKey" "MyValue") or Azure Key Vault. Never in source. - Run with
dotnet watch run. Reload on every code save. - Hit the relevant endpoint. If the change affects a route, a service, or middleware behavior, exercise it with a request.
Verification
- Open the structured logs. With Serilog or the default console provider, look for the registration line. Most ASP.NET Core services log their startup state at Information level.
- Hit a known-good endpoint to confirm nothing else broke. I keep a tiny "ping" endpoint in every app:
app.MapGet("/ping", () => "pong"). - Run your test suite if you have one.
dotnet test. - For production-bound changes, deploy to a staging slot first. App Service slots cost nothing extra on Standard tier and above.
Where this typically fails
- Middleware order. The single biggest cause of "I registered it, why isn't it running?" Compare against the default order in the Microsoft docs.
- Wrong lifetime. Scoped, Transient, Singleton, they mean different things in long-running hosts. Get this wrong and you'll see data leak between users or memory grow without bound.
- Config not loaded. Check the order in
builder.Configuration.Sources. User Secrets only load in Development by default.
Rollback
If the change is in Program.cs only, git revert is enough. If it touched appsettings.json, revert that too. If you've added new packages, run dotnet restore after the revert to clean up. Re-deploy. Smoke test. Move on.
Test in a sandbox tenant first. I keep a $5/month Azure dev/test subscription specifically for this kind of throwaway work, and it has paid for itself a hundred times over.
Operational notes
If you've got the basics down, here's the layer of practice that separates working from production-grade.
Team and runbook. Internal docs decay fast. I keep a CHANGELOG.md next to the code that touches this area, with a date and a one-line summary of every meaningful change.
Cost watch. On Azure pricing today, the network egress is usually the surprise. A B-series VM is ₹1,200-2,100 per month, but pull 500 GB of egress and you've added another ₹4,200.
Security pass. Add this to your threat model. Whatever this change touches: auth, data flow, config surface, needs to appear on the diagram, with the new trust boundary called out explicitly.
Observability. Add a metric. Counter, histogram, gauge. pick the right one. ASP.NET Core 10 has first-class OpenTelemetry support; wire it to your observability stack and watch the right things from day one.
Patterns I keep coming back to
Across many projects in ASP.NET Core, a few patterns repeat that are worth naming explicitly.
- The "smoke test on every deploy" pattern. A 10-line script that hits 5 endpoints, checks response code and latency, exits non-zero on failure. Run it as the last step of every CD pipeline. Catches 70% of post-deploy regressions before they reach a user.
- The "feature flag everything risky" pattern. Microsoft.FeatureManagement.AspNetCore (free, ships with the framework). Wrap any change that could blow up behind a flag, default off in production, flip the flag after the change is verified.
- The "twin environment" pattern. A staging environment that is byte-for-byte identical to production in configuration, with a fraction of the data. Costs maybe 20% extra on Azure if you size sensibly. Catches roughly 50% of "works locally, fails in prod" bugs.
- The "single source of secrets" pattern. Azure Key Vault or HashiCorp Vault. Not a .env file. Not appsettings.Production.json with values committed. Real secret storage with rotation policies.
Decisions worth revisiting periodically
Some choices made early in a project age fast. I keep a list of "look at this every six months" items per project. ASP.NET Core-flavored versions look like this:
- SDK and framework version. Are you on the current LTS? Microsoft's support window is fixed; falling behind two majors means you're paying interest in security patches.
- Dependency surface. Run
dotnet list package --outdatedquarterly. Each outdated package is a small risk; cumulatively, large risk. - Build time. If your CI builds creep past 8-10 minutes, the developer feedback loop slows enough to hurt productivity. Profile and trim.
- Test coverage and execution time. Coverage that climbs slowly is fine. Test suites that climb slowly toward 30 minutes is a warning sign, refactor or parallelize.
- Production error budget. If you're hitting your error budget consistently, slow feature work and pay down operational debt. If you're under-using your error budget, you're shipping too slowly.
Why I do it this way
Years ago I treated each topic in isolation. I'd read the docs, implement the feature, ship it, move on. The result was a lot of features that worked individually and didn't compose well. Today I default to: read the docs, sketch a diagram on paper or a digital whiteboard, identify the trust boundary, identify the failure mode, then implement. Ten extra minutes up front, hours saved down the road.
The other shift was treating tests as the design tool, not the verification tool. Writing the test first forces you to think about the API surface from the caller's perspective. By the time the test compiles, the design has been pressure-tested by your own most demanding consumer: a test that has to drive the feature without knowing the implementation.
Practical example: last month I rewrote a small reporting endpoint. The first draft was a single 60-line action method that pulled data, transformed it, and returned JSON. Tests forced me to split it into an IReportRepository, an IReportFormatter, and a thin controller. Same functionality, but now I can swap the formatter for HTML output by writing one new class and zero changes to the controller. That's the power of writing the test first.
References worth bookmarking
- Microsoft Learn: the canonical source. Whatever version of this page exists at learn.microsoft.com beats my summary.
- The ASP.NET Core GitHub repo's issues and discussions. Real bugs and real solutions, sometimes faster than the docs catch up.
- The .NET API browser at learn.microsoft.com/en-us/dotnet/api, perfect for "what does this method actually return when X."
- The official .NET blog at devblogs.microsoft.com/dotnet. explains the "why" behind changes that the API docs leave implicit.
How to apply this in practice
- Treat this as a starting point. Your tenant, SKU, region, and licence level all change the surface area in small but real ways.
- Run the procedure in a non-production environment first. A staging slot, a dev tenant, a sandboxed subscription, pick one and use it.
- Pin the version you implement against. When you commit to a design choice based on this page, write the date and the exact ASP.NET Core version into your ADR (architecture decision record).
- Cross-check the current Microsoft Learn page before rolling production. The product team updates docs often; what's true today may shift in two months.
Caveats and what to double-check
- ASP.NET Core terminology drifts. The same concept can have two or three names across docs cohorts written in different years.
- Some features in this area may still be in preview: confirm GA status before relying on it for production SLAs.
- Regional availability varies. A feature documented as "global" may actually roll out region by region across months.
- Pricing for ASP.NET Core-related services changes regularly. This page does not track pricing. Use the official Microsoft pricing calculator for the latest numbers.
Related work in your environment
- Document this reference in your team wiki along with which workloads currently depend on it.
- Set up a Microsoft Learn RSS feed or doc-change alert for the source page so your team is notified when Microsoft updates the canonical version.
- Add a periodic review to your governance cadence. Quarterly is a sensible default for ASP.NET Core.
FAQ
References
- Microsoft Learn - official documentation for ASP.NET Core
- Microsoft tech community forums and Q&A
- Azure / Microsoft 365 service health dashboards
Related fixes
Related guides worth a look while you sort this one out: