Solved

Debugging a C# Web program

Posted on 2016-07-27
3
60 Views
1 Endorsement
Last Modified: 2016-08-01
I have to modify a program that was written for the web.  When I run the code using Visual Studio there isn't a problem.  When I 'Publish' the code and run it from my Chrome browser I start to have problems.

When I have written ASP classic programs I am able to set a bunch of response.write to see what variables are.  In C# it doesn't appear I can do the same thing.  At least I can't figure out how to do it.

I have this line of code but I don't know where to put it to view it.  I am assuming it will need to be on the same page that is published.  For example, Cm.cpt is my connection string.  This is set in a page that is not shown to the user.  When the Login.aspx page is shown, how do I show the connection string?

 HttpResponse Response;

            Response = System.Web.HttpContext.Current.Response;
            Response.Write("Cm.cpt= " + Cm.cpt + "<br>");

Open in new window


How do I display it on my page?
1
Comment
Question by:huerita37
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 41733258
It should be possible to create the new web app in IIS, set the root folder of published application as the Working folder and then attach the VS debugger into IIS worker process. Then you may use breakpoints and look at variable values or evaluate expressions in Immediate window etc.
0
 

Author Comment

by:huerita37
ID: 41734750
pcelba - I may  not be understanding you completely because I am able to debug and step through the code while I run the program through VS.  My program runs fine when I run it through VS.  It's when it is live that I am having problems.  I want to see what certain variables are at particular times while the code is LIVE.

Can you confirm that your suggestion is for the LIVE program?
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 41734945
No, I cannot confirm it but how different is the application running under IIS on your local PC from the production one?

OK, if you really need values from the production then you may use Response.Write and you don't need to declare it as it is done in automatically generated metafiles.

Let suppose you are using C# language.

Simply create any ASPX page and to the code behind (.aspx.cs file) place the
Response.Write("Your text string");
into e.g. Page_Load method and that's it.

We are using this code to display Session keys:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class My_ShowSession : PageBase // System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        long total = 0;
        foreach (string key in Session.Keys)
        {
            object value = Session[key];
            long objectSize = ObjectSize(value);
            total += objectSize;
            Response.Write("Size:" + objectSize + " | " + key + "<BR/>");
            WriteDetails(value);
            Dictionary<string, object> s = Session[key] as Dictionary<string, object>;
            if (s != null)
            {
                if (s.ContainsKey("__timestamp"))
                {
                    Response.Write("&nbsp; &nbsp; TIMESTAMP is:" + ((DateTime)s["__timestamp"]).ToString()+"<br/>");
                }
            }
        }
        Response.Write("Total size:" + total);
    }

    private void WriteDetails(object value)
    {
       // format and write details here
    }


    private long ObjectSize(object obj)
    {
        try
        {
            System.IO.MemoryStream m = new System.IO.MemoryStream();
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            b.Serialize(m, obj);
            return m.Length;
        }
        catch { }
        return 0;
    }

}

Open in new window

And the ASPX code is very simple:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionInfo.aspx.cs" Inherits="My_ShowSession" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Session Info</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

Open in new window

0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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