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
*[500 Errors ("Internal Server Error")](#id-500-errors)
21
+
*[Boot Failed Errors](#boot-failed-errors)
22
22
23
23
{% hint style="info" %}
24
24
**Are you looking for a guide to create a custom maintenance page?**
25
25
26
26
This has been moved to a separate article: [Create a custom maintenance page](create-a-custom-maintenance-page.md).
27
27
{% endhint %}
28
28
29
-
## 404 errors
29
+
## 404 Errors
30
30
31
-
This kind of error can occur when something has been removed, when a path has been changed, or when the chosen path is invalid.
32
-
33
-
This method will use a 404 page created via the backoffice.
31
+
A 404 error occurs when a requested page cannot be found, usually due to deleted content, a changed URL, or an invalid path. In Umbraco, you can create and configure custom 404 pages using content from the backoffice.
34
32
35
33
### Create a 404 page in the backoffice
36
34
37
-
1. Navigate to the **Settings** section.
38
-
2. Create a new "_Document Type with Template_".
39
-
3. Name the Document Type **404**.
40
-
4. Adjust the alias to "Page404" before saving the Document Type. Umbraco will not allow you to create a Document Type with a numeric alias.
41
-
5.\[Optional] Add properties on the Document Type.
42
-
1. In most cases, the 404 not found page would be static.
43
-
6. Fill out the Template with your custom markup.
44
-
7. Create another **Document Type**, but create it without the Template.
45
-
8. Call this Document Type **Statuscodes**.
46
-
9. Open the **Structure** Workspace view.
47
-
10. Check the **Allow at root** option.
48
-
11. Add the **404 Page** Document Type as an **Allowed child note type**.
49
-
12. Navigate to the **Content** section.
50
-
13. Create a **Statuscodes** content item called **Statuscodes**.
51
-
14. Create a **404 Page** content item under the **Statuscodes** content.
52
-
53
-
### Set a custom 404 page in the configuration
54
-
55
-
Once that is done, the next step focuses on setting up the appropriate configuration.
56
-
57
-
1. Take note of the published error page's GUID.
58
-
2. Open the `appsettings.json` file in a code editor.
59
-
3. Add the `Error404Collection` section to `Umbraco:CMS:Content`, like shown below:
35
+
1. Go to the **Settings** section in the Umbraco backoffice.
36
+
2. Create a new **Document Type with Template**.
37
+
3. Name the Document Type *ErrorPage404*.
38
+
4.[Optional] Add any custom properties you want — though most 404 pages are static.
39
+
5. Click **Save**.
40
+
6. Go to the **Templates** folder.
41
+
7. Add your custom markup and design for the error page in the template. In this case, *ErrorPage404*.
42
+
8. Click **Save**.
43
+
44
+
### Create a Container for Status Code Pages
45
+
46
+
1. Create a new **Document Type**.
47
+
2. Name it **Statuscodes**.
48
+
3. Go to the **Structure** Workspace view.
49
+
* Enable **Allow at root**.
50
+
* Add the *ErrorPage404* Document Type as an **Allowed child node types**.
51
+
* Click **Choose**.
52
+
4. Click **Save**.
53
+
54
+
### Add the Content
55
+
56
+
1. Go to the **Content** section.
57
+
2. Create a new content node based on the **Statuscodes** Document Type and name it **Statuscodes**.
58
+
3. Click **Save** or **Save and Publish**.
59
+
4. Under it, create a child node using the *ErrorPage404* Document Type.
60
+
5. Name it *Page 404 Not Found* or similar.
61
+
* This will be the content shown when a 404 error occurs.
62
+
6. Click **Save** or **Save and Publish**.
63
+
64
+
### Configure the Error Page in `appsettings.json` file
65
+
66
+
After publishing the 404 page, you’ll need to connect it in your configuration.
67
+
68
+
1. Go to the **Info** tab of your *Page 404 Not Found* content item in the Backoffice.
69
+
2. Copy the **Id** of the page (for example: 9c2b5196-30cd-4416-ae30-94ac2afb1011).
70
+
3. Go to your project's `appsettings.json` file.
71
+
4. Add the `Error404Collection` setting to `Umbraco:CMS:Content`, like shown below:
60
72
61
73
```json
62
74
{
@@ -66,8 +78,7 @@ Once that is done, the next step focuses on setting up the appropriate configura
66
78
"Error404Collection": [
67
79
{
68
80
"Culture": "default",
69
-
// Replace the value for ContentKey with the GUID from step 1
@@ -76,17 +87,34 @@ Once that is done, the next step focuses on setting up the appropriate configura
76
87
}
77
88
```
78
89
79
-
{% hint style="info" %}
80
-
With this approach, you can set different 404 pages for specific languages (cultures) - such as `en-us`, `it` etc.
81
-
{% endhint %}
90
+
Replace the value for `ContentKey` with the ID of your own 404 page.
91
+
92
+
#### Support for Multilingual Sites
93
+
94
+
You can define different 404 pages for each language or culture (such as `en-us`, `da-dk`, and so on):
95
+
96
+
```json
97
+
"Error404Collection": [
98
+
{
99
+
"Culture": "en-us",
100
+
"ContentKey": "guid-for-english-404"
101
+
},
102
+
{
103
+
"Culture": "da-dk",
104
+
"ContentKey": "guid-for-danish-404"
105
+
}
106
+
]
107
+
```
108
+
109
+
Each entry maps a culture to its specific 404 page using the content’s GUID.
82
110
83
111
### Set a custom 404 page using IContentLastChanceFinder
84
112
85
-
It is also possible to set up a 404 error page programmatically using `IContentLastChanceFinder`. To learn more about `IContentLastChanceFinder` read the [Custom Routing](../implementation/custom-routing/)article.
113
+
It is also possible to set up a 404 error page programmatically using `IContentLastChanceFinder`. To learn more about `IContentLastChanceFinder`, read the [Custom Routing](../implementation/custom-routing/)article.
86
114
87
-
Before following this example, follow the [Create a 404 page in the backoffice](custom-error-page.md#create-a-404-page-in-the-backoffice) part. The example below will use the `Page404` alias of the Document Type to find and display the error page.
115
+
Before following this example, follow the [Create a 404 page in the backoffice](custom-error-page.md#create-a-404-page-in-the-backoffice) part. The example below will use the *errorPage404* alias of the Document Type to find and display the error page.
88
116
89
-
1. Create a new `.cs` file called `Error404Page` at the root of the project.
117
+
1. Create a new `.cs` file called *Error404Page* at the root of the project.
90
118
2. Add the following code to the newly created class:
@@ -142,35 +170,53 @@ public class Mycomposer : IComposer
142
170
```
143
171
{% endcode %}
144
172
145
-
## 500 errors
173
+
## 500 Errors
174
+
175
+
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:
176
+
177
+
* A template throws an error.
178
+
* A controller throws an unhandled exception.
179
+
* A request hits the application, but something fails during rendering or processing.
146
180
147
-
The following steps will guide you through setting up a page for internal server errors.
181
+
### Create a 500 error page in the Backoffice
148
182
149
-
### Create a 500-page in the backoffice
183
+
1. Go to the **Settings** section in the Umbraco backoffice.
184
+
2. Create a new **Document Type with Template** called *ErrorPage500*.
185
+
3.[Optional] Add any relevant properties to the Document Type.
186
+
4. Click **Save**.
187
+
5. Go to the **Templates** folder.
188
+
6. Add your custom markup and design for the error page in the template. In this case, *ErrorPage500*.
189
+
7. Click **Save**.
150
190
151
-
The first step is to create the content and structure for it in the Umbraco backoffice.
191
+
### Create a Container for Status Code Pages
152
192
153
-
1. Access the Umbraco Backoffice.
154
-
2. Navigate to the **Settings** section.
155
-
3. Create a new **Document Type with Template** called **500**.
156
-
4.\[Optional] Add relevant properties to the Document Types and define the Template.
157
-
5. Fill out the Template with your custom markup.
158
-
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).
159
-
1. This step can be skipped if you already have a content structure for error content nodes in the project.
160
-
7. Add the **500** Document Type as an **Allowed child node type** on the **Statuscode** Document Type.
161
-
8. Navigate to the **Content** section.
162
-
9. Create a **Statuscodes** content item if one does not exist already.
163
-
10. Create a **500** content item under the **Statuscodes** content.
193
+
1. Create a new **Document Type**.
194
+
2. Name it **Statuscodes**.
195
+
3. Go to the **Structure** Workspace view.
196
+
* Enable **Allow at root**.
197
+
* Add the *ErrorPage500* Document Type as an **Allowed child node types**.
198
+
* Click **Choose**.
199
+
4. Click **Save**.
164
200
165
-
### Configure the 500 error page programmatically
201
+
### Add the Content
166
202
167
-
The next step in this guide is to configure the 500 pages to be shown when an internal server error occurs.
203
+
1. Go to the **Content** section.
204
+
2. Create a new content node based on the **Statuscodes** Document Type and name it **Statuscodes**.
205
+
3. Click **Save** or **Save and Publish**.
206
+
4. Under it, create a child node using the *ErrorPage500* Document Type.
207
+
5. Name it *Page 500* or similar.
208
+
* This will be the content shown when a 500 error occurs.
168
209
169
-
1. Create a folder in the root of your Umbraco project, called `Controllers`.
170
-
2. Create a file in this folder, called `ErrorController.cs`.
210
+
### Configure the 500 Error Page Programmatically
211
+
212
+
To ensure that the 500 page is shown during server errors, you’ll need to configure a custom error controller and route handling.
213
+
214
+
1. Create a folder called `Controllers` in the root of your Umbraco project.
215
+
2. Add a new file called `ErrorController.cs` in the `Controllers` folder.
171
216
3. Add the following code to the file:
172
217
173
218
{% code title="ErrorController.cs" %}
219
+
174
220
```csharp
175
221
usingMicrosoft.AspNetCore.Mvc;
176
222
@@ -193,29 +239,35 @@ public class ErrorController : Controller
193
239
}
194
240
}
195
241
```
242
+
196
243
{% endcode %}
197
244
198
245
{% hint style="info" %}
199
-
**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).
246
+
Replace _YourProjectNamespace_ with the actual project namespace. In Visual Studio, you can right-click the project and select **Sync Namespaces**.
200
247
{% endhint %}
201
248
202
-
4. Add an entry in `appSettings.json`for the new "Error" route:
249
+
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:
215
267
216
268
{% code title="Program.cs" %}
269
+
217
270
```csharp
218
-
...
219
271
WebApplicationapp=builder.Build();
220
272
221
273
if (builder.Environment.IsDevelopment())
@@ -227,30 +279,61 @@ else
227
279
app.UseExceptionHandler("/error");
228
280
}
229
281
```
282
+
230
283
{% endcode %}
231
284
232
285
{% hint style="info" %}
233
-
To **test this locally**, in Visual Studio replace `app.UseDeveloperExceptionPage();` by `app.UseExceptionHandler("/error");`. Otherwise, you will get the default error page.
286
+
To test locally, replace `app.UseDeveloperExceptionPage();`with`app.UseExceptionHandler("/error");`. Otherwise, you'll get the default .NET error page during development.
234
287
{% endhint %}
235
288
236
-
### How to trigger a 500 error for testing
289
+
### Testing Your 500 Error Page
290
+
291
+
To trigger a 500 error on your site, try introducing a rendering error:
292
+
293
+
For example, if a Document Type has a property called `test`, it is normally rendered as:
294
+
295
+
```csharp
296
+
@Model.Value("test")
297
+
```
298
+
299
+
To trigger a 500 error, modify it to:
300
+
301
+
```csharp
302
+
@Model.ValueTest("test")
303
+
```
304
+
305
+
This will generate a server-side error, allowing you to verify that your custom 500 page is displayed correctly.
306
+
307
+
### Handling app startup failures
308
+
309
+
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.
310
+
311
+
#### Why can't the app serve an error page?
312
+
313
+
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.
314
+
315
+
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.
316
+
317
+
To handle these types of issues:
237
318
238
-
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");`
319
+
* Configure your web server (IIS, NGINX, Apache) to serve a static HTML 500 page when the app fails to respond.
320
+
* Use uptime monitoring to catch failed starts.
321
+
* Check Umbraco logs in `App_Data/Logs` for startup errors.
239
322
240
-
## Errors with booting a project
323
+
## Boot Failed Errors
241
324
242
325
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.
243
326
244
327
You will be presented with a generic error page when there is an error during boot.
245
328
246
-

This page can be overwritten with a custom BootFailed HTML page. Follow the steps below to set it up:
331
+
You can replace the default BootFailed page with a custom static `BootFailed.html`. Follow the steps below to set it up:
249
332
250
333
1. Open your project files.
251
334
2. Navigate to `wwwroot/config/errors`
252
335
1. If this folder does not exist already, create it.
253
-
3. Add a new file called **`BootFailed.html`**.
336
+
3. Add a new file called *BootFailed.html*.
254
337
4. Add your custom markup to the file.
255
338
256
339
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