B
Brad Baker
I'm trying to create a custom ASP.NET custom error page however I am having
some problems. Here is what I have done:
1) I've created a page called default.aspx with the following code to
stimulate an error:
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e) {
throw new Exception ("Test Exception");
}
</script>
2) I've edited my web.config file custom errors as follows:
<customErrors
mode="On"
defaultRedirect="errorreport.aspx"
/>
3) My errorreport.aspx contains the following code:
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e) {
HttpContext ctx = HttpContext.Current;
Exception ex = Server.GetLastError().GetBaseException();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString () +
"<br>Source: " + ex.Source +
"<br>Message: " + ex.Message +
"<br>Stack trace: " + ex.StackTrace;
Response.Write (errorInfo);
}
</script>
When I access default.aspx, I get redirected to asperrorreport.aspx as
expected but the following error is generated on the errorreport.aspx page:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Line 12: Exception ex = Server.GetLastError().GetBaseException();
I believe this is because the "ex" variable is null. What I don't understand
is why it's null? What am I missing?
Thanks,
Brad
some problems. Here is what I have done:
1) I've created a page called default.aspx with the following code to
stimulate an error:
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e) {
throw new Exception ("Test Exception");
}
</script>
2) I've edited my web.config file custom errors as follows:
<customErrors
mode="On"
defaultRedirect="errorreport.aspx"
/>
3) My errorreport.aspx contains the following code:
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e) {
HttpContext ctx = HttpContext.Current;
Exception ex = Server.GetLastError().GetBaseException();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString () +
"<br>Source: " + ex.Source +
"<br>Message: " + ex.Message +
"<br>Stack trace: " + ex.StackTrace;
Response.Write (errorInfo);
}
</script>
When I access default.aspx, I get redirected to asperrorreport.aspx as
expected but the following error is generated on the errorreport.aspx page:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Line 12: Exception ex = Server.GetLastError().GetBaseException();
I believe this is because the "ex" variable is null. What I don't understand
is why it's null? What am I missing?
Thanks,
Brad