Return 404 status code in asp.net with content on page

Share:
The HTTP 404 Not Found client error response code indicates that the server can't find the requested resource.

Links which lead to a 404 page are often called broken or dead links.

Sometimes you don't want to redirect to an error-page but render the requested page. A good example is a sold out items in an online shop. The correct status code for google would be 404, but you surely want to display the product to your visitors together with an message such as "Sorry, Sold out" instead of redirecting to a general 404 page.

If you have Response.StatusCode = 404; in your code behind file, then ASP.NET will redirect to your error page.

An easy and quick solution to avoid the redirect is to write below code:


General Redirection in web.config file:

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments