Sirdots
asked on
Generic error page not showin when an error is encountered - asp.net c# web forms
On page load I am testing displaying an error message
page called Error.htm. I am throwing an exception when
the page loads. The error message is logged but the
Error.htm does not display. How can I make this display?
I thought by placing it in the web.config file it should
be fine.
I am using log4net to log the errors.
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
try
{
throw new System.InvalidOperationExc eption("Lo gfile cannot be read-only");
}
catch (Exception ex)
{
log.Info("Page load event- default page..... ");
log.Error("Page load event- default page " + ex.Message) ;
}
}
}
Here is the entry in my web.config file...
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm "></custom Errors>
page called Error.htm. I am throwing an exception when
the page loads. The error message is logged but the
Error.htm does not display. How can I make this display?
I thought by placing it in the web.config file it should
be fine.
I am using log4net to log the errors.
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
try
{
throw new System.InvalidOperationExc
}
catch (Exception ex)
{
log.Info("Page load event- default page..... ");
log.Error("Page load event- default page " + ex.Message) ;
}
}
}
Here is the entry in my web.config file...
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm
ASKER
Thanks I tried the throw and it didnt work. Here is what I got below highlighting the line 301 where throw is.
Logfile cannot be read-only
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc eption: Logfile cannot be read-only
Source Error:
Line 299: log.Info("Page load event- default page..... ");
Line 300: log.Error("Page load event- default page " + ex.Message) ;
Line 301: throw;
Line 302: }
Line 303: }
Logfile cannot be read-only
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc
Source Error:
Line 299: log.Info("Page load event- default page..... ");
Line 300: log.Error("Page load event- default page " + ex.Message) ;
Line 301: throw;
Line 302: }
Line 303: }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are very correct. It works well now after changing the mode to on
Open in new window
In general, it would make more sense to have your error page be an ASP.NET page and have it log the exception. That way you don't have to have the logging code scattered throughout your application.