Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx"
- />
- Exception ex = Server.GetLastError();
- if (ex != null)
- {
- if (ex.GetBaseException() != null)
- ex = ex.GetBaseException();
- }
- <customErrors mode="RemoteOnly" defaultRedirect="~/errors/GeneralError.aspx" redirectMode="ResponseRewrite" />
- void Application_Error(object sender, EventArgs e)
- {
- // Code that runs when an unhandled error occurs
- Exception ex = Server.GetLastError();
- Application["TheException"] = ex; //store the error for later
- Server.ClearError(); //clear the error so we can continue onwards
- Response.Redirect("~/myErrorPage.aspx"); //direct user to error page
- }
- <system.web>
- <customErrors mode="RemoteOnly" defaultRedirect="~/myErrorPage.aspx">
- </customErrors>
- </system.web>
- protected void Page_Load(object sender, EventArgs e)
- {
- // ... do stuff ...
- //we caught an exception in our Global.asax, do stuff with it.
- Exception caughtException = (Exception)Application["TheException"];
- //... do stuff ...
- }
- //direct user to error page
- Server.Transfer("~/ErrorPages/Oops.aspx");
- }
- protected void LoadError(Exception objError)
- {
- if (objError != null)
- {
- StringBuilder lasterror = new StringBuilder();
- if (objError.Message != null)
- {
- lasterror.AppendLine("Message:");
- lasterror.AppendLine(objError.Message);
- lasterror.AppendLine();
- }
- if (objError.InnerException != null)
- {
- lasterror.AppendLine("InnerException:");
- lasterror.AppendLine(objError.InnerException.ToString());
- lasterror.AppendLine();
- }
- if (objError.Source != null)
- {
- lasterror.AppendLine("Source:");
- lasterror.AppendLine(objError.Source);
- lasterror.AppendLine();
- }
- if (objError.StackTrace != null)
- {
- lasterror.AppendLine("StackTrace:");
- lasterror.AppendLine(objError.StackTrace);
- lasterror.AppendLine();
- }
- ViewState.Add("LastError", lasterror.ToString());
- }
- }
- protected void btnReportError_Click(object sender, EventArgs e)
- {
- SendEmail();
- }
- public void SendEmail()
- {
- try
- {
- MailMessage msg = new MailMessage("webteam", "webteam");
- StringBuilder body = new StringBuilder();
- body.AppendLine("An unexcepted error has occurred.");
- body.AppendLine();
- body.AppendLine(ViewState["LastError"].ToString());
- msg.Subject = "Error";
- msg.Body = body.ToString();
- msg.IsBodyHtml = false;
- SmtpClient smtp = new SmtpClient("exchangeserver");
- smtp.Send(msg);
- }
- catch (Exception ex)
- {
- lblException.Text = ex.Message;
- }
- }
Add Comment
Please, Sign In to add comment