Click here to Skip to main content
15,898,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I have a question. I'm a new in ASP.NET MVC. Does somebody know how to show custom page if path to action is uncorrect?

For example, if the URL is like http://www.example.com/Product/blahhh, and app doesn't have blahh action, and I want to show my custom error page to the user.
Posted
Updated 11-Oct-14 11:07am
v2

Custom Errors in ASP.NET[^]
Custom Errors Mode in Web.config allows you to manage custom error page to be shown.
There are three modes in general:

  • Off
  • On
  • Remote only

Another attribut that is used is "defaultRedirect", this is an optional attribute that is used to redirect the browser to the default error page if any, else generic errors are shown to

users.

C#
<customerrors mode="" defaultredirect="Error/Index">
</customerrors>

Another method is:
C#
<customerrors mode="" defaultredirect="">
<error statuscode="400" redirect="NotFound.htm" />
<error statuscode="500" redirect="InternalServerError.htm" />
</customerrors>

Please go through this article and then you can redirect the user to a default Not Found page designed by you.
Thanks
:)
 
Share this answer
 
Sadly there is no thing as a custom page, but there are custom error pages in ASP.NET. You can use custom error pages and redirect the user to your custom error pages inside the application so that he can see the error page or whatever the message you're trying to show to him.

Here is a tutorial on how you can create custom error pages in ASP.NET MVC, http://benfoster.io/blog/aspnet-mvc-custom-error-pages[^].

Give it a try, you will understand the basic implementation and usage of web.config file and the Code Behind to work together to cause the user to move to the custom page if there is a 404 error.

Http 404 error is raised if there is no resource file found in the directory.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900