I have a great and important problem with Web.Config, I need to see the Error of my page and resolve it in asp.net web form and web config, but when Error Occurred, I see an
Here is sample code how you can display exceptions on custom page.
First create Default.aspx with button:
Add following code for button click event:
protected void Button1_Click(object sender, EventArgs e)
{
throw new Exception("Sample Exception on my Page");
}
Second create ErrorPage.aspx with label:
And code for error page:
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex != null && ex.InnerException != null)
{
Label1.Text = string.Format("An error occured: {0}", ex.InnerException.Message);
}
}
And finally place following configuration in web.config:
Compile and start with Default.aspx. Click your button and error will be shown on your custom page.
Happy coding!