Does ASP, C#, VB.NET have a way to retrieve what line its on in code as its processing commands?
1 <% 2 response.write("Your on line " & retreiveCurrentLineNumber) 3 %>
Output: Your on line 2
You can do this:
var line = new StackFrame(0, true).GetFileLineNumber();
Note there are several caveats to this.
- You will need to make sure the source file and PDB are reachable.
- This will get you the current line of the method you are in, not exactly where you are.
- The Jit may perform optimizations that result in incorrect information, such as a method being inlined.
For VB.NET it's the same thing:
Dim line As Integer = New StackFrame(0, True).GetFileLineNumber()
As far as Classic ASP goes - I don't believe this is possible.