Forum Moderators: phranque
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