You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -75,9 +74,22 @@ Once that is done, the next step focuses on setting up the appropriate configura
75
74
}
76
75
```
77
76
78
-
{% hint style="info" %}
79
-
With this approach, you can set different 404 pages for specific languages (cultures) - such as `en-us`, `it` etc.
80
-
{% endhint %}
77
+
In the above code sample, replace the value for `ContentKey` with the GUID from step 1.
78
+
79
+
With this approach, you can set different 404 pages for specific languages/cultures (such as `en-us`, `da-dk`, and so on):
80
+
81
+
```json
82
+
"Error404Collection": [
83
+
{
84
+
"Culture": "en-us",
85
+
"ContentKey": "guid-for-english-404"
86
+
},
87
+
{
88
+
"Culture": "da-dk",
89
+
"ContentKey": "guid-for-danish-404"
90
+
}
91
+
]
92
+
```
81
93
82
94
### Set a custom 404 page using IContentLastChanceFinder
83
95
@@ -141,35 +153,38 @@ public class Mycomposer : IComposer
141
153
```
142
154
{% endcode %}
143
155
144
-
## 500 errors
156
+
## 500 Errors
145
157
146
-
The following steps will guide you through setting up a page for internal server errors.
158
+
This section guides you in setting up a custom page for handling internal server errors (500 errors) in your Umbraco site. This setup works when:
147
159
148
-
### Create a 500-page in the backoffice
160
+
* A template throws an error.
161
+
* A controller throws an unhandled exception.
162
+
* A request hits the application, but something fails during rendering or processing.
149
163
150
-
The first step is to create the content and structure for it in the Umbraco backoffice.
164
+
### Create a 500 error page in the Backoffice
151
165
152
166
1. Access the Umbraco Backoffice.
153
167
2. Navigate to the **Settings** section.
154
-
3. Create a new **Document Type with Template** called **500**.
155
-
4.\[Optional] Add relevant properties to the Document Types and define the Template.
168
+
3. Create a new **Document Type with Template** called *500*.
169
+
4.[Optional] Add relevant properties to the Document Types and define the template layout.
156
170
5. Fill out the Template with your custom markup.
157
-
6. Follow steps 6-9 in the [Create a 404 page in the backoffice](custom-error-page.md#create-a-404-page-in-the-backoffice).
158
-
1. This step can be skipped if you already have a content structure for error content nodes in the project.
171
+
6. Follow steps 6-9 in the [Create a 404 page in the backoffice](custom-error-page.md#create-a-404-page-in-the-backoffice) section.
172
+
* You can skip this if you already have a structure for status code content nodes.
159
173
7. Add the **500** Document Type as an **Allowed child node type** on the **Statuscode** Document Type.
160
-
8.Navigate to the **Content** section.
174
+
8.Go to the **Content** section.
161
175
9. Create a **Statuscodes** content item if one does not exist already.
162
-
10. Create a **500**content item under the **Statuscodes** content.
176
+
10. Create a new content node of type **500** under the **Statuscodes** content node.
163
177
164
-
### Configure the 500 error page programmatically
178
+
### Configure programmatic error handling
165
179
166
-
The next step in this guide is to configure the 500 pages to be shown when an internal server error occurs.
180
+
Now configure the application to display the 500 error page when internal server errors occur.
167
181
168
-
1. Create a folder in the root of your Umbraco project, called `Controllers`.
169
-
2. Create a file in this folder, called `ErrorController.cs`.
182
+
1. Create a folder called `Controllers`in the root of your Umbraco project.
183
+
2. Create a new file called `ErrorController.cs` in the `Controllers` folder.
170
184
3. Add the following code to the file:
171
185
172
186
{% code title="ErrorController.cs" %}
187
+
173
188
```csharp
174
189
usingMicrosoft.AspNetCore.Mvc;
175
190
@@ -192,29 +207,35 @@ public class ErrorController : Controller
192
207
}
193
208
}
194
209
```
210
+
195
211
{% endcode %}
196
212
197
213
{% hint style="info" %}
198
-
**Namespace:**Replace _YourProjectNamespace_ with the actual project name. In Visual Studio, you can use _Sync Namespaces_ from the project context menu (in _Solution Explorer_ View).
214
+
Replace _YourProjectNamespace_ with the actual project name. In Visual Studio, you can use _Sync Namespaces_ from the project context menu (in _Solution Explorer_ View).
199
215
{% endhint %}
200
216
201
-
4. Add an entry in `appSettings.json`for the new "Error" route:
217
+
4. Add the `/error/` route to the list of reserved paths in the `appSettings.json`file:
5. Update `Program.cs`to ensure the error route is triggered by unhandled exceptions:
214
235
215
236
{% code title="Program.cs" %}
237
+
216
238
```csharp
217
-
...
218
239
WebApplicationapp=builder.Build();
219
240
220
241
if (builder.Environment.IsDevelopment())
@@ -226,30 +247,59 @@ else
226
247
app.UseExceptionHandler("/error");
227
248
}
228
249
```
250
+
229
251
{% endcode %}
230
252
231
253
{% hint style="info" %}
232
-
To **test this locally**, in Visual Studio replace `app.UseDeveloperExceptionPage();` by `app.UseExceptionHandler("/error");`. Otherwise, you will get the default error page.
254
+
To test this locally, replace `app.UseDeveloperExceptionPage();` by `app.UseExceptionHandler("/error");`. Otherwise, you will get the default error page.
233
255
{% endhint %}
234
256
235
-
### How to trigger a 500 error for testing
257
+
### Trigger a 500 error (for testing)
258
+
259
+
To trigger a 500 error, change a `Model.Value` property in your template. For example, if your Document Type has a property called `test`you would normally render it with:
260
+
261
+
```csharp
262
+
@Model.Value("test")
263
+
```
264
+
265
+
To deliberately cause an error, change it to something invalid like:
266
+
267
+
```csharp
268
+
@Model.ValueTest("test")
269
+
```
270
+
271
+
This should throw an error, triggering your custom 500 page.
272
+
273
+
### Handling app startup failures
274
+
275
+
When Umbraco fails to start, you may see a blank screen or receive a `500.30` or `502.5` error. These indicate the web application crashed or failed to initialize.
276
+
277
+
#### Why can't the app serve an error page?
278
+
279
+
During startup, Umbraco relies on the ASP.NET Core pipeline. If the app crashes before this pipeline is fully initialized, it can't handle requests or serve custom error pages. That's why you can't rely on Umbraco or ASP.NET Core routing to show error content at this point as it has already failed. For more information, see the [Handle errors in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling) documentation.
280
+
281
+
Instead, the web server itself (IIS, NGINX, Apache, and so on) must serve a static fallback 500 page. This page is independent of the application and helps communicate the issue to users when the site is down.
282
+
283
+
To handle these types of issues:
236
284
237
-
You can trigger a 500 error on your front end by changing a `Model.Value` property in your template. For example, on a Document Type with a property called `test`. The way to render it in the front would be `Model.Value("test");` To trigger a 500 error page you can add anything after Value such as `Model.ValueTest("test");`
285
+
* Configure your web server (IIS, NGINX, Apache) to serve a static HTML 500 page when the app fails to respond.
286
+
* Use uptime monitoring to catch failed starts.
287
+
* Check Umbraco logs in `App_Data/Logs` for startup errors.
238
288
239
-
## Errors with booting a project
289
+
## Boot Failed Errors
240
290
241
291
Sometimes you might experience issues with booting up your Umbraco project. This could be a brand new project, or it could be an existing project after an upgrade.
242
292
243
293
You will be presented with a generic error page when there is an error during boot.
244
294
245
-

This page can be overwritten with a custom BootFailed HTML page. Follow the steps below to set it up:
297
+
You can replace the default BootFailed page with a custom static `BootFailed.html`. Follow the steps below to set it up:
248
298
249
299
1. Open your project files.
250
300
2. Navigate to `wwwroot/config/errors`
251
301
1. If this folder does not exist already, create it.
252
-
3. Add a new file called **`BootFailed.html`**.
302
+
3. Add a new file called *BootFailed.html*.
253
303
4. Add your custom markup to the file.
254
304
255
305
The `BootFailed.html` page will only be shown if debugging is disabled in the `appsettings.json` file. Debugging is handled using the **Debug** key under `Umbraco:CMS:Hosting`:
0 commit comments