How I implemented the formatted 404 page for Sitecore Docker MVP Site
1. Fork the MVP repo:
2. You are allowed to select your github account:
3. Since I already forked this repo, I'm taken to my forked repo page:
4. In the above page, you should be able to notice that this fork is one commit behind my upstream, which is nothing but the MVP repo. Fetch and merge the changes so that your forked repo will have the latest changes:
5. Once the merge is successful, the latest changes are in my fork:
Note that you must specify the forked repo and not the original repo in the above dialog!
7. Once you clone, you should be able to see the latest commit in your local repo:
10. Fill the .env file, up.ps1 and launch the Docker instance as per the github readme page or my earlier blogs:
11. Next, access the existing not found page:
12. Then, setup the 404 content items as per my earlier blog (page loads in XPE for reference):
13. Now, it is time to switch over to Visual Studio 2019 and make some code changes to display this shiny new 404 page!
13.a Single line change to existing CustomContextItemResolver:
13.b Add the related setting to the config:
14. All done, time to Build Solution and while I compile, usually keep my docker logs open in PS window!
A 200 in the last line means all fine!
15. I check my 404 page in the web instance:
16. Check a valid page to be sure the 404 page works as per logic:
17. All good so far but the status code is still 200 and not 404 in the not found page!
18. To correct the 200 status code issue, add the following line in the pipeline processor,
19. Also, note that the old view returned from the default controller is no more needed:
20. Compile and check the page result, that does the trick:
21. Push the branch up, raise a PR and just relax since life is short ;)
Few more observations:
If you make a change to the Default Controller and save then you will see the usefulness of the logs since you can see an error in log due to the cs file save:
Note that you will get the below 404 message if Docker container is still warming-up and hasn't returned 200 yet in the logs so, watching logs will give peace of mind!
Note that you can access containers in Visual Studio 2019 as follows:
View -> Other windows -> Containers
I usually use the VS containers to check the Docker container file system!
Few errors/resolutions for reference:
Comments
Post a Comment