进入任何不存在的页面时。它给出错误-页面没有正确重定向。它没有重定向到httperorpage。aspx
这个代码正确吗?它会进入自定义错误页面还是会发送邮件。
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("krishnamohan.p@sun.com"));
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
}
}
相对路径是否有效?Response.Redirect (~/HttpErrorPage.aspx);