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"))
return;
Response.Redirect("HttpErrorPage.aspx");
}
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");
EmailTheException(ex);
Server.ClearError();
}
private void EmailTheException(Exception ex)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(new System.Net.Mail.MailAddress("[email protected]"));
mail.Subject = "An Application Exception has Occurred.";
mail.Body = ex.ToString();
System.Net.Mail.SmtpClient MailServer = new System.Net.Mail.SmtpClient();
try
{
// MailServer.Send(mail);
}
catch (System.Net.Mail.SmtpException smtpEx)
{
//write logging code here and capture smtpEx.Message
}
}