title: How to send error info mail, if any error occurred in web application
body: <p>Here the scenario is I have  many <code>.aspx pages</code> if any page gives error, it will redirect to an error page</p>
  
  <p><code>Web.config</code>:</p>
  
  <pre><code>&lt;customErrors mode="On" defaultRedirect="customErrorPage.aspx"&gt;
         &lt;error statusCode="404" redirect="Error404.aspx" /&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>If I get 404 error it will redirect to <code>Error404.aspx</code> works fine.</p>
  
  <p>But if their any other error <em>(forbidden, connectionlost, service unavailable etc)</em> then I want to redirect to <code>customErrorPage.apsx</code>.</p>
  
  <p>I want to send an email with error information (error pagename, error statusCode) when the custom error page is displayed and later after few minutes it will auto redirect user to <code>login.aspx</code>.</p>
  
  <p>I have tried (not working) </p>
  
  <pre><code>void Application_Error(object sender, EventArgs e) 
  { 
          ex = (HttpException)Server.GetLastError();
          int errorcode = ex.GetHttpCode();
    //    Response.Redirect("Errorpage.aspx?id='" + errorcode + "'&amp;msg='" + message + "'");
  }
  </code></pre>
  
  <p>My custom error page</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
           getUrl = HttpContext.Current.Request.Url.ToString();
          // string error=  HttpContext.Current.Error.ToString();
          //   HtmlMeta meta = new HtmlMeta();
         //   HtmlHead head = (HtmlHead)Page.Header;
          // meta.HttpEquiv = "refresh";
          //   meta.Content = "10;   url=Login.aspx";
          //  head.Controls.Add(meta);
  }
  
  protected void Page_UnLoad(object sender, EventArgs e)
  {
         //send mail function
         Email.Send("abc@asa.com", "Error Log", "custom error", true);
  }
  </code></pre>
  
  <p>ALSO let me know if their is any other good way to this </p>