Custom 404 page not found

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
Amer
User
Posts: 79

Custom 404 page not found

Post by Amer »

Hello,
In my app, I want to handle ALL not-found/incorrect URLs by showing a generic NotFound Page that contains a simple message and a link to the home page, instead of the ugly default browser page.

So I have created a custom file with the needed content and gave it the URL "/not-found".

Now how should I tell the app to route all not-found URLs to my custom page URL ("/not-found")? and at what server event?

Thank you in advance.


MichaelG
User
Posts: 1111

Post by MichaelG »

By default, 404 errors are handled by the error page. If you want to use your own, you will need to customize the Startup.cs page as explained in:
https://docs.microsoft.com/en-us/aspnet ... etcore-5.0


Amer
User
Posts: 79

Post by Amer »

Thank you for the reply,
Yes , I know it is easy using Visual Studio,
but in my question, I have indicated that I want to do it form inside AspnetMaker itself, because editing the project after creating it using Visual Studio is not an acceptable solution, simply because it will be overwritten on the next project regeneration, which I do a lot.

How to do that from inside AspnetMaker ?


MichaelG
User
Posts: 1111

Post by MichaelG »

If you do not want to modify the generated codes, I don't think there is a simple way to do this except by modifying the template file "Startup.cs".


Amer
User
Posts: 79

Post by Amer »

Modifying the template file "Startup.cs" seems a great idea,

There is a lot of templating stuff there (I think it is for the Node generating engine), and I don't want to subvert them, so please guide me on what to change exactly and where.

All I need is to handle only the 404 error and redirect it to the (~/not-found) page.

Thank you for your valuable help and support.


MichaelG
User
Posts: 1111

Post by MichaelG »

Please read help file topic: Customizing Template to understand how to customize the template. Look for the changes you need to make in the template file "Startup.cs".


Post Reply