Deployed ASP.NET Core app shows only the generic Error page
Fix it fast
Most common cause, 1 of 3The server runs as Production, so only the log has the exception
Find the log entry with event ID 1 from ExceptionHandlerMiddleware wherever the host keeps console output, and fix the exception it names.
# Program.cs keeps the safe default
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}Short answer
An error occurred while processing your request is the template's /Error page. With no environment set, ASP.NET Core runs as Production and UseExceptionHandler hides the exception but logs it. On .NET 10 and 11 a common trigger is a setting that exists only in appsettings.Development.json, launchSettings.json or user secrets. Read the logged exception, then supply that value in Production.
Which cause do you have?
Run the app on your own machine as Production and without the launch profile, then repeat the request that failed. The console shows the real exception right after the unhandled-exception line, and the page looks exactly like the server's.
dotnet run -e ASPNETCORE_ENVIRONMENT=Production --no-launch-profileThen find the line you see in this list and open its fix:
- 1The server runs as Production, so only the log has the exception
The browser shows a Request ID, the same request works under dotnet run, and nobody has read the server log yet - 2Variables were defined only in launchSettings.json
The logged exception names a missing setting, and that key appears under environmentVariables in Properties/launchSettings.json - 3The value comes from user secrets or a Development settings file
dotnet user-secrets list prints the key, or the key sits only in appsettings.Development.json
What does the error look like?
Error. An error occurred while processing your request.Swapping to the Development environment displays detailed information about the error that occurred.An unhandled exception has occurred while executing the request.
Cause 1 of 3
The server runs as Production, so only the log has the exception
You seeThe browser shows a Request ID, the same request works under dotnet run, and nobody has read the server log yet
Check
An error occurred while processing your request is what the template's Error page renders after UseExceptionHandler catches an unhandled exception outside Development. Microsoft's docs note that if neither DOTNET_ENVIRONMENT nor ASPNETCORE_ENVIRONMENT is set, Production is the default, and the middleware logs the exception it catches.
grep -n "Development" Properties/launchSettings.jsonFix
Find the log entry with event ID 1 from ExceptionHandlerMiddleware wherever the host keeps console output, and fix the exception it names. Do not switch the deployed site to Development to read it; the template itself warns that this exposes exception details to visitors.
# Program.cs keeps the safe default
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}Verify
After the fix, the failing URL returns a normal page and the count of unhandled-exception lines in the log stops growing.
grep -c "An unhandled exception has occurred while executing the request" app.logConfirmed by learn.microsoft.com
Cause 2 of 3
Variables were defined only in launchSettings.json
You seeThe logged exception names a missing setting, and that key appears under environmentVariables in Properties/launchSettings.json
Check
Microsoft's environments page says launchSettings.json is only used on the local development machine and isn't deployed when the app is published. Any variable a launch profile sets, such as an API base URL or a feature flag, exists for dotnet run and F5 but not on the server, so the request that reads it throws.
grep -n -A8 "environmentVariables" Properties/launchSettings.jsonFix
Copy each variable the app needs from the profile into the server's own environment or service definition. Nested keys use a double underscore, which configuration turns into a colon.
# on the server, one line per key the profile used to set
export Payments__ApiBaseUrl="https://api.example.com"Verify
Locally, a run that skips the profile but exports the same variables serves the page without the generic error.
Payments__ApiBaseUrl="https://api.example.com" dotnet run -e ASPNETCORE_ENVIRONMENT=Production --no-launch-profileConfirmed by learn.microsoft.com
Cause 3 of 3
The value comes from user secrets or a Development settings file
You seedotnet user-secrets list prints the key, or the key sits only in appsettings.Development.json
Check
WebApplication.CreateBuilder adds user secrets only when the environment name is Development, and of the per-environment JSON files it reads just the one named after the running environment. On a Production host both sources are skipped, so the key reads as null and the code using it fails mid-request.
dotnet user-secrets listFix
Give the server every listed key through appsettings.Production.json, an environment variable or the host's secret store. A missing connection string has its own page with the exact null-string error.
dotnet user-secrets list
# then on the server, for example:
export Smtp__Password="..."Verify
The log stops recording unhandled exceptions for that request, and the page renders on the server.
Smtp__Password="..." dotnet run -e ASPNETCORE_ENVIRONMENT=Production --no-launch-profileConfirmed by learn.microsoft.com
How do I stop it coming back?
- Run the app once with -e ASPNETCORE_ENVIRONMENT=Production before every release, so missing Production settings fail on your machine first.
- Keep Development-only values out of appsettings.json and list every required Production key in the deployment checklist or pipeline variables.
- Ship console or file logs from the server to a place you can search by Request ID, the value the Error page prints.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Raheeb, Loade Driver, Dhero.