How to Perform debugging and tracing in asp.net
In this article we will discuss 2 important things of ASP.NET . Today we will see how can we get the detailed error messages while we execute the application. We will also see about Tracing in asp.net. We will see it with the help of an example.
Debugging is actually performed to get the error messages in detail while executing the
application. We can enable or disable this feature on a particular page or through
out the application.
You can enable the debugging feature by setting Debug = true in page directive.
<%@ Page Language="C#" Debug="true" %>
If we want to set it on application level we cans et in web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
Suppose we write the below code in code behind and set debug="true"
public static SqlConnection con;
public static SqlCommand cmd;
string c = ConfigurationManager.ConnectionStrings["HospitalConnectionString"].ConnectionString;
public string count;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(c);
}
we will get the error message like snapshot in errormessage document linked below.
Similarly if we want to see the trace messages we can enable or disable it on page
or application level by setting Trace = "true" in page directive.
<%@ Page Language="C#" Debug="true" Trace="true" %>
Suppose we write the below code in code behind and set Trace="true"
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Label1.Text;
}
we will get the trace message like snapshot in tracemessage document linked below.