Home > Custom Error > Server.getlasterror() Is Null

Server.getlasterror() Is Null


Ideally we should return something a little friendlier to our site visitors than the error pages built in to ASP.NET/IIS, perhaps offering some advice on why the resource may not exist In these cases we need to set up custom error pages in IIS (note that this only works in IIS 7+). ASP.NET redirects any unhandled errors except HTTP 404 errors to this page. For local users, the page displays a complete exception report.

The ExceptionUtility class in the example has two static methods: one to log the exception, and one to notify system administrators. Requested URL: /foo/bar Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.33440 Not exactly friendly, is it? In Global.aspx: void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs //direct user to error page Server.Transfer("~/ErrorPages/Oops.aspx"); } In Oops.aspx: protected void Page_Load(object sender, EventArgs C#VB Copy <%@ Page Language="C#" %>