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
Copy file name to clipboardExpand all lines: 16/umbraco-cms/tutorials/custom-error-page.md
+76-60Lines changed: 76 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,45 +28,58 @@ This has been moved to a separate article: [Create a custom maintenance page](cr
28
28
29
29
## 404 Errors
30
30
31
+
{% hint style="warning" %}
32
+
To follow this guide successfully, ensure you're using Umbraco version 16.1 or later, as it fixes a regression from version 16.0. For more details, see the [Breaking changes](https://our.umbraco.com/download/releases/1610) section in the Release Notes.
33
+
{% endhint %}
34
+
31
35
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.
32
36
33
-
### Create a 404 page in the backoffice
37
+
### Create a Page Not Found page in the backoffice
34
38
35
-
1. Go to the **Settings** section in the Umbraco backoffice.
39
+
1. Go to the **Settings** section in the backoffice.
36
40
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.
41
+
3. Name the Document Type *Page Not Found*.
42
+
4.[Optional] Add custom properties (for example, title, message), though most 404 pages are static.
39
43
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*.
44
+
6. Go to the **Templates** folder and edit the generated template.
45
+
7. Add your custom markup and design for the error page in the template.
42
46
8. Click **Save**.
43
47
44
-
### Create a Container for Status Code Pages
48
+
### [Optional] Create a Container for Error Pages
49
+
50
+
You can create a *Page Not Found* page directly in your content tree, or organize it within a container for error pages. Using a container allows for better content organization, especially if you plan to handle multiple status codes (for example, 404, 500, maintenance, and so on). Both options work as long as the page ID is referenced correctly in the `appsettings.json` file.
45
51
46
52
1. Create a new **Document Type**.
47
-
2. Name it **Statuscodes**.
53
+
2. Name it *Error Pages Container*.
48
54
3. Go to the **Structure** Workspace view.
49
55
* Enable **Allow at root**.
50
-
* Add the *ErrorPage404* Document Type as an **Allowed child node types**.
56
+
* Add the *Page Not Found* Document Type as an **Allowed child node types**.
51
57
* Click **Choose**.
52
58
4. Click **Save**.
53
59
60
+

61
+
54
62
### Add the Content
55
63
56
64
1. Go to the **Content** section.
57
-
2. Create a new content node based on the **Statuscodes** Document Type and name it **Statuscodes**.
65
+
2. Create a new content node based on the *Error Pages Container* Document Type. For example *Home Page*.
58
66
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.
67
+
68
+

69
+
70
+
4. Create a child node, using the *Page Not Found* Document Type.
71
+
5. Name it *Page Not Found* or similar.
61
72
* This will be the content shown when a 404 error occurs.
62
73
6. Click **Save** or **Save and Publish**.
63
74
75
+

76
+
64
77
### Configure the Error Page in `appsettings.json` file
65
78
66
-
After publishing the 404 page, you’ll need to connect it in your configuration.
79
+
After publishing the *Page Not Found*page, connect it in the configuration:
67
80
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).
81
+
1. Go to the **Info** tab of the*Page Not Found* content item in the Backoffice.
82
+
2. Copy the **Id** of the page (for example: 06cf09c8-c83a-4dd7-84e5-6d98d51e4d12).
70
83
3. Go to your project's `appsettings.json` file.
71
84
4. Add the `Error404Collection` setting to `Umbraco:CMS:Content`, like shown below:
72
85
@@ -78,7 +91,7 @@ After publishing the 404 page, you’ll need to connect it in your configuration
@@ -87,11 +100,11 @@ After publishing the 404 page, you’ll need to connect it in your configuration
87
100
}
88
101
```
89
102
90
-
Replace the value for `ContentKey` with the ID of your own 404 page.
103
+
Replace the value for `ContentKey` with the ID of your own *Page Not Found* page.
91
104
92
105
#### Support for Multilingual Sites
93
106
94
-
You can define different 404 pages for each language or culture (such as `en-us`, `da-dk`, and so on):
107
+
You can define different error pages for each language or culture (such as `en-us`, `da-dk`, and so on):
95
108
96
109
```json
97
110
"Error404Collection": [
@@ -112,61 +125,64 @@ Each entry maps a culture to its specific 404 page using the content’s GUID.
112
125
113
126
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.
114
127
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.
128
+
Before following this example, follow the [Create a Page Not Found page in the backoffice](#create-a-page-not-found-page-in-the-backoffice) part. The example below will use the *Page Not Found* alias of the Document Type to find and display the error page.
116
129
117
-
1. Create a new `.cs` file called *Error404Page* at the root of the project.
130
+
1. Create a new `.cs` file called *PageNotFound* at the root of the project.
118
131
2. Add the following code to the newly created class:
0 commit comments