How to handle page not found exception message in asp.net MVC 5.0 in user friendly ways


WordPress.com

If we have asp.net mvc 5.0 application and we are searching some different page on browser then we will get the exception message.

“The resource cannot be found” I.e HTTP 404 status code.

To display this error message as user friendly we can install the “NotFoundMVC” Nuget package in Visual studio like this

NotFound

Now go to the web config file and delete the this line of code. This is the problem in this NuGet package, which is creating some invalid code in web config file.

WebConfig

Now this package will create the Not found page for you.

This will also add the required code in web config file like this

Now run the application with wrong controller/Action name. It will give user friendly error message like this

Limitation of Control
This control does not handle the other error message. It will handle on status code 404. For other error we have to implement separate error handle approach.

Summary:
I hope this post will help to implement the user friendly error message for http status code 404.

WordPress.com

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.