[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Whats the easy way to debug asp.net

Hi,

How could I debuging on asp.net pages that not running of iis server directly.
a way to make alert LIKE window.alert("sometext");

Thanks
0
fsze88
Asked:
fsze88
  • 3
  • 3
1 Solution
 
quizwedgeCommented:
Typically what I use in this situation is either printing values of variables or "hey, I got here" messages to the screen or writing them to a file which I can manually check. Obviously, the second way is better in a production environment.
0
 
fsze88Author Commented:
how?
0
 
quizwedgeCommented:
I'm not sure if you're using VisualBasic.NET, C#.NET or some other .NET language, but here's a simple set of logging functions. I didn't originally write them and can't remember where I got them from, but fairly certain it had a pretty permissive license that would be fine in a commercial application. If someone comes across this and knows where it came from, let me know. I'll gladly give credit. It's been years since I found this code.

The code below is written in VisualBasic.NET. To add a line to the log, you would do the following.

FileAppend("C:\my_log_file.txt", "The value of the variable X is " & X & vbCrLf)

Open in new window


If X is 5, this will write the following to C:\my_log_file.txt: The value of variable X is 5. The vbCrLf at the end is so that the next FileAppend will put the text on the next line.

Code to make the logging work:

 Public Function FileExists(ByVal mPath As String) As Boolean
        Return System.IO.File.Exists(mPath)
    End Function

    Public Sub DeleteMe(ByVal source As String)
        System.IO.File.Delete(source)
    End Sub

    Public Sub FileAppend(ByVal mFile As String, ByVal mText As String)
        If Not FileExists(mFile) Then
            FileSave(mFile, mText)
            Exit Sub
        End If
        Dim fStream As System.IO.FileStream = New System.IO.FileStream(mFile, System.IO.FileMode.Append)
        Dim sWriter As System.IO.StreamWriter = New System.IO.StreamWriter(fStream)
        sWriter.BaseStream.Seek(0, System.IO.SeekOrigin.End)
        sWriter.Write(mText)
        sWriter.Flush()
        sWriter.Close()
        fStream.Close()
    End Sub

    Public Sub FileSave(ByVal mFile As String, ByVal mText As String)
        If FileExists(mFile) Then DeleteMe(mFile)
        Dim fStream As System.IO.FileStream = New System.IO.FileStream(mFile, System.IO.FileMode.OpenOrCreate)
        Dim sWriter As System.IO.StreamWriter = New System.IO.StreamWriter(fStream)
        sWriter.Write(mText)
        sWriter.Flush()
        sWriter.Close()
        fStream.Close()
    End Sub

Open in new window

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
fsze88Author Commented:
"hey, I got here" messages to the screen
0
 
fsze88Author Commented:
Sometimes is not works well by Response.Write()
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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