Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Deployed ASP.NET Core app shows only the generic Error page

Your error

Error. An error occurred while processing your request.2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The 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.

Fix
# Program.cs keeps the safe default
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to .NET 11.0.0, .NET 10.0.15 LTS, ASP.NET Core web app (Razor Pages) template
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
dotnet run -e ASPNETCORE_ENVIRONMENT=Production --no-launch-profile

Then find the line you see in this list and open its fix:

  1. 1The server runs as Production, so only the log has the exceptionThe browser shows a Request ID, the same request works under dotnet run, and nobody has read the server log yet
  2. 2Variables were defined only in launchSettings.jsonThe logged exception names a missing setting, and that key appears under environmentVariables in Properties/launchSettings.json
  3. 3The value comes from user secrets or a Development settings filedotnet 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.

Check
grep -n "Development" Properties/launchSettings.json

Fix

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.

Fix
# 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.

Verify
grep -c "An unhandled exception has occurred while executing the request" app.log

Confirmed by learn.microsoft.com

Did this fix it?

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.

Check
grep -n -A8 "environmentVariables" Properties/launchSettings.json

Fix

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.

Fix
# 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.

Verify
Payments__ApiBaseUrl="https://api.example.com" dotnet run -e ASPNETCORE_ENVIRONMENT=Production --no-launch-profile

Confirmed by learn.microsoft.com

Did this fix it?

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.

Check
dotnet user-secrets list

Fix

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.

Fix
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.

Verify
Smtp__Password="..." dotnet run -e ASPNETCORE_ENVIRONMENT=Production --no-launch-profile

Confirmed by learn.microsoft.com

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.