?
Solved

Debugging a C# Web program

Posted on 2016-07-27
3
Medium Priority
?
64 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 2000 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 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