Global.asax in C#

Posted on 2007-10-12
Last Modified: 2012-06-27
Given the below global.asax in C# code:

<%@ Application Language="C#" %>
<script runat="server" >
public void Application_Error(object sender, EventArgs e)
  string mess= "Error in Path :"+Request.Path ; //Get the path of the page
  mess+="\n\n Error Raw Url :"+Request.RawUrl ; //Get the QueryString along with the Virtual Path

  //Create an Exception object from the Last error that occurred on the server
  Exception myError =Server.GetLastError();

  mess+="\n\n Error Message :"+myError.Message; //Get the error message
  mess+="\n\n Error Source :"+myError.Source;  //Source of the message
  mess+="\n\n Error Stack Trace :"+myError.StackTrace; //Stack Trace of the error
  mess+="\n\n Error TargetSite :"+myError.TargetSite; //Method where the error occurred

  //Create a Mail Message
  System.Web.Mail.MailMessage errorMessage = new System.Web.Mail.MailMessage();
  errorMessage.To ="";
  errorMessage.Subject="Web Application Error Reporting!";

  System.Web.Mail.SmtpMail.Send(errorMessage); //Send the message

How can the namespace "System.Web.Mail" be declared with "using" or "import" at the top and be taken out
of the code body? Thanks.
Question by:ksfok
    LVL 21

    Accepted Solution

    Try using <%@ Import Namespace="System.Web.Mail" %>
    LVL 96

    Assisted Solution

    by:Bob Learned
    I would move that code into a class that you can define the method and add a using block at the top of the module.


    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now