Global.asax in C#

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 ="webmaster@yoursite.com";
  errorMessage.From="error@yoursite.com";
  errorMessage.Subject="Web Application Error Reporting!";
  errorMessage.Body=mess;

  System.Web.Mail.SmtpMail.Send(errorMessage); //Send the message
}
</script>

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.
ksfokAsked:
Who is Participating?
 
surajgupthaCommented:
Try using <%@ Import Namespace="System.Web.Mail" %>
0
 
Bob LearnedCommented:
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.

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.