Creating a 404 page not found error in c sharp asp net


ASP.NET is a popular programming language used for developing web applications. One common requirement in web is to create a custom 404 page not error. In this article, we will explore how to this using C# in ASP.NET.

Step 1: Handling the Error

The first step is to handle the 404 error in your ASP.NET application. This can be done by adding the following code to your web.config file:


In the above code, we have set the mode to “On” and specified the defaultRedirect page as “Error.aspx”. We have also an error element with a statusCode of 404 and a redirect page of “NotFound.aspx”.

Step 2: Creating the Custom 404 Page

Next, we need to create the custom 404 page. In this example, let's create a new ASP.NET Web Form “NotFound.aspx”.

In the above code, we have created a simple HTML page with a heading and a paragraph to display the error message.

Step 3: Testing the Custom 404 Page

Now that we have set up the error handling and created the custom 404 page, let's test it. To do this, we can intentionally navigate to a non-existent page in our application.


When you navigate to the above URL, you should be to the custom 404 page we created.


In this article, we have learned how to create a custom 404 page not found error in C# ASP.NET. By handling the error in the web.config file and creating a custom page, we can a better user when users encounter a page that does not .

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents