Tips & Tricks for ASP.NET - C#

Google site Search
ASP.NET Email Error Global.asa Get last Error Details

Show the visitors any friendly message and send email to you with the page name and error details.

WEBCONFIG
-----------

<customErrors mode="On" defaultRedirect="404.aspx"></customErrors>

GLOBAL.ASAX
------------


    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

Exception objErr = Server.GetLastError().GetBaseException();
 string err = "<font face=Arial size=2><p>Error Message:" + objErr.Message.ToString() + "</p>" +
                     "<p>Error in: " + Request.Url.ToString() + "</p></font>";

// Email the Error
       
System.Net.Mail.MailMessage mlMsg = new System.Net.Mail.MailMessage("from email id", "to email id", "Subject", err);
       
System.Net.Mail.SmtpClient smtpCl = new System.Net.Mail.SmtpClient("xx.xx.xxx.xxx"); // IP address of the server
mlMsg.IsBodyHtml = true;
             
smtpCl.Send(mlMsg);       
       
       

    }


404.aspx
-----------


display a friendly message to the visitors, like page not found etc



Arvixe offers ASP.net hosting that's good for testing plugins. Here is a good arvixe review if you want to know more.

Comments
Catherine Says:-
“ I was looking for this for a long time. This helps to show the visitors a customised error message and I can get the actual reason ”
 
 
Matthew Says:-
“ very nice thax ”
 
 
Geoffrey Says:-
“ cheers ”
 
 
Hannah Says:-
“ cool site, veryyyyyyy good ”
 
 
Write Comments
Name  
Email    
Comments  

Other Titles