while entering any page which is not exist. its giving error - The page isn't redirecting properly .its not redirecting to HttperrorPage.aspx

is this code correct ? will it go custom error page or it will send mail.

void Application_Error(object sender, EventArgs e) 
    Exception ex = Server.GetLastError();
    if (ex.GetType() == typeof(HttpException))
        if (ex.Message.Contains("NoCatch") || ex.Message.Contains("maxUrlLength"))


    Response.Write("<h1 style='text-align:center'>Sorry There is Some Technical Problems Occured.Try again Later </h2>\n");
    Response.Write("<h1 style='text-align:center'>We Will get back to u shortly</h2>\n");
private void EmailTheException(Exception ex)
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    mail.To.Add(new System.Net.Mail.MailAddress("krishnamohan.p@sunlightit.com"));
    mail.Subject = "An Application Exception has Occurred.";
    mail.Body = ex.ToString();

    System.Net.Mail.SmtpClient MailServer = new System.Net.Mail.SmtpClient();
       // MailServer.Send(mail);
    catch (System.Net.Mail.SmtpException smtpEx)
        //write logging code here and capture smtpEx.Message

Related posts

Recent Viewed