Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 507685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:49:48+00:00 2026-05-13T06:49:48+00:00

I am examining our legacy system, and there is a method that sends an

  • 0

I am examining our legacy system, and there is a method that sends an e-mail when there is an exception.

It looks like this:

        string strError = "Error in: " + Request.Path + 
            "\nUrl: " + Request.RawUrl + "\n\n";

        // Get the exception object for the last error message that occured.
        Exception ErrorInfo = Server.GetLastError().GetBaseException();
        strError += "Error Message: " + ErrorInfo.Message + 
            "\nError Source: " + ErrorInfo.Source + 
            "\nError Target Site: " + ErrorInfo.TargetSite + 
            "\n\nQueryString Data:\n-----------------\n";

        // Gathering QueryString information
        for (int i = 0; i < Context.Request.QueryString.Count; i++) 
            strError += Context.Request.QueryString.Keys[i] + ":\t\t" + Context.Request.QueryString[i] + "\n";
        strError += "\nPost Data:\n----------\n";

        // Gathering Post Data information
        for (int i = 0; i < Context.Request.Form.Count; i++) 
            strError += Context.Request.Form.Keys[i] + ":\t\t" + Context.Request.Form[i] + "\n";
        strError += "\n";

        if (User.Identity.IsAuthenticated) strError += "User:\t\t" + User.Identity.Name + "\n\n";

        strError += "Exception Stack Trace:\n----------------------\n" + Server.GetLastError().StackTrace + 
            "\n\nServer Variables:\n-----------------\n";

        // Gathering Server Variables information
        for (int i = 0; i < Context.Request.ServerVariables.Count; i++) 
            strError += Context.Request.ServerVariables.Keys[i] + ":\t\t" + Context.Request.ServerVariables[i] + "\n";
        strError += "\n";

        // Sending error message to administration via e-mail
    SmtpClient smtp = new SmtpClient();
    MailMessage email = new MailMessage();
    email.From = new MailAddress("noreply@mysite.com");
    email.To.Add("me@mysite.com");
    email.Subject = "Site error notification";
    email.Body = strError;

    smtp.Send(email);

This may or may not be hideous, some of the code in our system is beyond shocking, but I have never attempted to investigate the best way to report errors. What do you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:49:48+00:00Added an answer on May 13, 2026 at 6:49 am

    you can try elmah

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a secure alternative to mkdir() for C? I am examining some code
I'm examining the feasibility of porting an existing Windows MFC control to OS X/Carbon.
Using T4 I want to generate some code based on examining what files are
I just upgraded a VS 2005 project to VS 2008 and was examining the
Problem Summary When run in batch mode, my user identity is lost but (like
Unusual interview question I got. Being completely agnostic about the platform, what are some
I wrote a program which solves some kind of optimization problem. I have been
I've inherited a site with hundreds of scattered HTML and non-framework PHP files, which
I have been attempting to capture the event when a user clicks on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.