Forum Moderators: phranque

Message Too Old, No Replies

Help w/ Custom Error Handling / Sending Error Emails

         

jmarch51

9:42 pm on Nov 6, 2006 (gmt 0)

10+ Year Member



We recently had our website switched over to an Apache Web Server and I need to set up custom error pages. Mind you I have absolutely no experience with the Apache Web Server nor any experience with ASP.net so I am pretty much learning as I go. Should the following work

I added this to web config file


<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="/error.aspx">
<error statusCode="404" redirect="/404.aspx"/>
<error statusCode="403" redirect="/403.aspx"/>
</customErrors>
</system.web>
</configuration>

For the 404.aspx page I have the following code: (Once the page is accessed I should have an error email sent to me)


<%@ language="C#" EnableSessionState="false" AutoEventWireup="false" %>
<%@ Import Namespace="System.Web.Mail" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head><title></title></head>

<body>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<%
String message = "<p>" + Request.Url.ToString()
+ "<pre><font color='red'>" + Server.GetLastError().ToString() + "</pre>"
+ "</font>";

Response.Write(message);
Response.Write("We could not locate the page you requested. The administrator of the site has been notified.");

MailMessage mail = new MailMessage();
mail.From = "automated@company.com";
mail.To = "webmaster.march@comapany.com";
mail.Subject = "Site Error";
mail.Body = message;
mail.BodyFormat = MailFormat.Html;
SmtpMail.Send(mail);

Server.ClearError();

%>
</td>
</tr>
</table>
</body>
</html>

When I try to go to the 404.aspx page directly via the website I get the following error:


Description: Error processing request.
Error Message: HTTP 500.

Stack Trace: System.NullReferenceException: Object reference not set to an instance of an object
in <0x0009e> ASP._404_aspx:__RenderTree (System.Web.UI.HtmlTextWriter __output, System.Web.UI.Control parameterContainer)
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_HtmlTextWriter_Control (System.Web.UI.HtmlTextWriter,System.Web.UI.Control)
in <0x00026> System.Web.UI.Control:RenderChildren (System.Web.UI.HtmlTextWriter writer)
in <0x00011> System.Web.UI.Control:Render (System.Web.UI.HtmlTextWriter writer)
in <0x00099> System.Web.UI.Control:RenderControl (System.Web.UI.HtmlTextWriter writer)
in <0x002f1> System.Web.UI.Page:InternalProcessRequest ()
in <0x000a1> System.Web.UI.Page:ProcessRequest (System.Web.HttpContext context)

Any clue as to why I am getting this error? Sorry if this is a stupid question but like I said I have no experience with the Apache Web Server or ASP.net

Thanks in advace

Jeff