connectseekers.com

Tuesday, 20 May 2014

Custom Error Page in Asp.Net Using C#.Net

5/20/2014 - By Pranav Singh 0

Whenever we develop any asp.net application error occurs when ever we perform some unwanted operation. So in this application I will show you how you can develop a custom error page when ever some error occurs user will automatically redirected to the custom error page in your ap.net application. In this tutorial I will give an example by using C#.Net.



So for this article first we will select our defaut.aspx  page add the below mention code to throw the exception :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectDemo_Asp.et
{
    public partial class _Default : System.Web.UI.Page
    {
        /// <summary>
        /// Custom error page resirect
        /// Raising error by deviding value with 0
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            int x = 1;
            int y = 0;
            int value = x / y;
        }
    }
}

In above code we are dividing a number by zero, this operation is not allowed in c#. so when we execute the page on that case we will get below mention error.



Now we will put a custom error page. For this we will create a custom error page(error.aspx) and make some changes in our web.config file.



<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
       <system.web>
              <customErrors mode="On" defaultRedirect="Error.aspx"/>
              <compilation debug="true"/>
  </system.web>
</configuration>


In above code we have added an error.aspx page this page will be displayed when some error will occur. Now run the application. You will get the below mention error and after error you will not get above mention error page. You will be automatically redirected to error.aspx page.


Now your custom Error page will appear





Tags: , ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top