- Hosting Article & Tutorial

ASP.NET Hosting Tips – How To Let User Know That There’s An Error in Specific Page

How To Let User Know That There’s An Error in ASP.NET Page – Let’s assume that you have a controller in which different types of errors may occur. In this scenario, redirecting the user to a generic error page may not make much sense and may not help user solve the problem if the problem is coming because of data entered by them.

ASP.NET Hosting Tips How To Let User Know That There's An Error in Specific Page

Displaying error specific page and displaying helpful information on that page would make much sense so that the user understand what actually is happening and what action he/she may take to solve the problem. The other side of this scenario can be showing error page based on error type assigned to team members. Similarly, there can be many other scenario one can think of where we need to show error page specific to that type of error.

Let us see how to achieve this functionality:


In the above controller method, you have added a HandleError attribute where 1st parameter is ExceptionType (the type of exception you want to catch) and 2nd parameter is the View to show when this type of exception occurs in this action method.


Above is the code for the View that renders when NullReferenceException occurs. As this view has been kept inside the ~/Views/Shared folder so the View name specified in the 2nd parameter of the HandleError attribute of the action method doesn’t need to specify the path along with this view name.

Similarly, other HandleError attribute can be applied to the same action method for different types of error.

Notice the above action method where we have two HandleError attributes for different types of error, both with respective view. Note that all these will work only when customErrors mode is “On” in the web.config file.

ASP.NET Hosting with HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. They deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. They have customers from around the globe, spread across every continent. They have served the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

awards-03.pngHostForLIFE.eu is Microsoft No #1 Recommended Windows and ASP.NET Hosting in European Continent. Their service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and many top European countries.

HostForLIFE.eu Hosting is the first host to offer its customer all the new features of the ASP.NET 4.6 Hosting. You can simply deploy your ASP.NET 4.6 website via our world-class Control Panel or conventional FTP tool. This ASP.NET 4.6 Hosting is part of HostForLIFE.eu service and it is provided free of charge.