2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by GajananPund
0

If you don't already have a Global.asax then right click on the project and select "Add -- New Item" then select "Global Application Class". Modify your Global.asax:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Net.Mail;
using System.Net;

namespace daniweb.asp
{
  public class Global : System.Web.HttpApplication
  {

    protected void Application_Start(object sender, EventArgs e)
    {

    }

    protected void Session_Start(object sender, EventArgs e)
    {

    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {

    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {

    }

    protected void Application_Error(object sender, EventArgs e)
    {
      Exception lastError = Server.GetLastError();
      lastError = (lastError == null || lastError.InnerException == null ? lastError : lastError.InnerException);
      if (lastError != null)
      {
        int? httpErrorCode = default(int?);
        {
          HttpException httpEx = (lastError as HttpException);
          if (httpEx != null)
          {
            httpErrorCode = httpEx.GetHttpCode();
          }
        }


        MailMessage m = new MailMessage();
        m.From = new MailAddress("sender@host.com", "sender");
        m.To.Add("recipient@host.com");
        m.Subject = "Web Exception" + (httpErrorCode == null ? string.Empty : " HTTP ERROR: " + ((int)httpErrorCode).ToString("F0"));
        m.Body = lastError.Message + Environment.NewLine + Environment.NewLine +
          lastError.StackTrace;
        SmtpClient smtp = new SmtpClient("email.server.com");
        smtp.Credentials = new NetworkCredential("username", "password");
        smtp.Send(m);
      }
    }

    protected void Session_End(object sender, EventArgs e)
    {

    }

    protected void Application_End(object sender, EventArgs e)
    {

    }
  }
}

Edited by sknake: n/a

0

If you don't already have a Global.asax then right click on the project and select "Add -- New Item" then select "Global Application Class". Modify your Global.asax:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Net.Mail;
using System.Net;

namespace daniweb.asp
{
  public class Global : System.Web.HttpApplication
  {

    protected void Application_Start(object sender, EventArgs e)
    {

    }

    protected void Session_Start(object sender, EventArgs e)
    {

    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {

    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {

    }

    protected void Application_Error(object sender, EventArgs e)
    {
      Exception lastError = Server.GetLastError();
      lastError = (lastError == null || lastError.InnerException == null ? lastError : lastError.InnerException);
      if (lastError != null)
      {
        int? httpErrorCode = default(int?);
        {
          HttpException httpEx = (lastError as HttpException);
          if (httpEx != null)
          {
            httpErrorCode = httpEx.GetHttpCode();
          }
        }


        MailMessage m = new MailMessage();
        m.From = new MailAddress("sender@host.com", "sender");
        m.To.Add("recipient@host.com");
        m.Subject = "Web Exception" + (httpErrorCode == null ? string.Empty : " HTTP ERROR: " + ((int)httpErrorCode).ToString("F0"));
        m.Body = lastError.Message + Environment.NewLine + Environment.NewLine +
          lastError.StackTrace;
        SmtpClient smtp = new SmtpClient("email.server.com");
        smtp.Credentials = new NetworkCredential("username", "password");
        smtp.Send(m);
      }
    }

    protected void Session_End(object sender, EventArgs e)
    {

    }

    protected void Application_End(object sender, EventArgs e)
    {

    }
  }
}

Problem Solved
Thank you very much Scott

regards,

Gajanan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.