void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
Exception objErr = Server.GetLastError().GetBaseException(); //获取错误
string err ="Error Caught in Application_Error event\n" +
"Error in:" + Request.Url.ToString() +
"\nError Message:"+ objErr.Message.ToString() +
"\nStack Trace:"+ objErr.StackTrace.ToString();
//将捕获的错误写入windows的应用程序日志中,可从事件查看器中访问应用程序日志。
System.Diagnostics.EventLog.WriteEntry("Test2", err, System.Diagnostics.EventLogEntryType.Error);
Server.ClearError();
//设置发件人信箱,及显示名字
System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("[email protected]", "HeyJob.net系统消息");
//设置收件人信箱,及显示名字
System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress("[email protected]", "系统");
//创建一个MailMessage对象
System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage(from, to);
oMail.Subject = "异常错误信息Heyjob.net"; //邮件标题
oMail.Body = err; //邮件内容
oMail.IsBodyHtml = true; //指定邮件格式,支持HTML格式
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//邮件采用的编码
oMail.Priority = System.Net.Mail.MailPriority.High;//设置邮件的优先级为高
//发送邮件服务器
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com"; //指定邮件服务器
client.Credentials = new System.Net.NetworkCredential("[email protected]", "*****");//指定服务器邮件,及密码
//发送
oMail.Dispose(); //释放资源
}
{
// 在出现未处理的错误时运行的代码
Exception objErr = Server.GetLastError().GetBaseException(); //获取错误
string err ="Error Caught in Application_Error event\n" +
"Error in:" + Request.Url.ToString() +
"\nError Message:"+ objErr.Message.ToString() +
"\nStack Trace:"+ objErr.StackTrace.ToString();
//将捕获的错误写入windows的应用程序日志中,可从事件查看器中访问应用程序日志。
System.Diagnostics.EventLog.WriteEntry("Test2", err, System.Diagnostics.EventLogEntryType.Error);
Server.ClearError();
//设置发件人信箱,及显示名字
System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("[email protected]", "HeyJob.net系统消息");
//设置收件人信箱,及显示名字
System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress("[email protected]", "系统");
//创建一个MailMessage对象
System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage(from, to);
oMail.Subject = "异常错误信息Heyjob.net"; //邮件标题
oMail.Body = err; //邮件内容
oMail.IsBodyHtml = true; //指定邮件格式,支持HTML格式
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//邮件采用的编码
oMail.Priority = System.Net.Mail.MailPriority.High;//设置邮件的优先级为高
//发送邮件服务器
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com"; //指定邮件服务器
client.Credentials = new System.Net.NetworkCredential("[email protected]", "*****");//指定服务器邮件,及密码
//发送
oMail.Dispose(); //释放资源
}
void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string error = "发生异常页: " + Request.Url.ToString() + "<br>";
error += "异常信息: " + objErr.Message + "<br>";
Server.ClearError();
Application["error"] = error;
Response.Redirect("~/ErrorPage/ErrorPage.aspx");
}发送邮件是否有问题