在重定向到自定义错误页面时,页面无法正确重定向

时间:2015-06-04 16:34:06

标签: c# asp.net redirect smtpclient

输入任何不存在的页面时

。给出错误 - 页面没有正确重定向。没有重定向到HttperrorPage.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
    }
}

1 个答案:

答案 0 :(得分:0)

相对路径会起作用吗?的Response.Redirect(&#34;〜/ HttpErrorPage.aspx&#34);