• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1675
  • Last Modified:

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.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.
2 Solutions
Try using <%@ Import Namespace="System.Web.Mail" %>
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.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now