Identify current step in page life cycle - asp.net

Is there a way to see where exactly a given piece of code is executing with regards to the current Page life cycle? Closest thing I can think of is to look at the call stack in the debugger and attempt to determine from there. But I thought there might be some standard way?

You can use Trace. If you want to know from code, use StackTrace.

Related

System.Web.UI.Control.LoadRecursive() - Insufficient stack to continue executing the program safely.

I have an ASP.NET web application developed in C# and .Net v4. When you login in and leave for the page for some 15-20 minutes, I get the "Insufficient stack to continue executing the program safely."
According to my knowledge, there is no way you can try-catch the stackoverflow in .Net. I would imagine that recursive loading of web page and active session checking leading to this error (maybe a bad coding practice). I have also added the screenshot as i am able to figure it out from Stack trace. If anyone help me in this,it will be helpful.
I think I have found the solution. Still the test. Check this Link and this
they really looks promising. I will keep you guys updated when I succeed..
Thank you all for your help.
The problem is this callstack is right at the end of the stack.
A few things to look for:
Is there anywhere in your code where you are using .FindControl(string id)?
If so, is it locating a control and then trying to locate it further?
Are you dynamically creating controls, like for <asp:Placeholder/> controls.
It can be recursive when you reference the parent from within a nested control, which then gets re-referenced by the parent.

Exploring a ASP.NET website's code

I have been set a new project at work and have been given the code beforehand to give it a good look. Since time is limited, can anyone please give me the best way to get a good feel of the project. What are the things I should be looking for within the code?
Thanks.
Well, first I'd get the app running and get a sense of the functionality (the business functionality) of the application. If you're not familiar with the business functionality, keep notes on your questions.
Next examine the code. things like:
1. Database access methodology (ASP.NET Core, Linq2SQL, EF, NHibernate etc.)
2. Take a look at the database and the data model
3. Examine the areas you're not comfortable with in regards the ASP.NET/C# etc.
Keep a note of questions you have through this phase. If they want you to hit the ground running, you'll need your questions answered. Asking the right (intelligent) questions shows you've spent time examining the code (as they would expect)
Set a breakpoint at the page_load or init event handler of a page of interest and step through the code (F11) to see where it goes and what it does.

How do I get TextWriterTraceListener to output times much like the standard tracing does?

I'm trying to analyze some running times for various methods in my default.aspx.cs page. I need to use TextWriterTraceListener.
I have it set up so that output is being redirected to the file. However, the data isn't what I want.
As far as I can tell if you simply enable tracing and have the trace appended to the bottom of the webpage you get this nice table with times in between trace calls. It's these times that I care about. An example can be seen here...
http://dotnetperls.com/trace-basics-aspnet
Using TextWriterTraceListener say, for example, I add to the top of Page_Init
System.Diagnostics.Trace.TraceInformation("Begin Page_Init");
and to the bottom...
System.Diagnostics.Trace.TraceInformation("End Page_Init");
here's the output I get...
WebDev.WebServer.EXE Information: 0 : Begin Page_Init
WebDev.WebServer.EXE Information: 0 : End Page_Init
This isn't helpful to me. For one, I don't know what the 0 means. Maybe it's the time, but it's not recognizing anything less than 1 second? I don't know.
I can't find any good resources on this, but I know I have to be missing something, this seems not very useful as is. How do I get times without resorting to some sort of trickery?
Edit: I should note that I found this...
Formatting trace output
However, it seems the consensus is to use log4net or roll your own. Is this really the answer? I'm unsure how this method of tracing could be that useful without any type of timing.
Ok, well writing out Stopwatch values works fine so I guess I'll just do that. It just seems like it should work just the same as when you enable Tracing to the page. I guess not though.
Anyway as far as I can tell, the answer is to use your own method of timing in conjunction with TextWriterTraceListener.

How can I export trace.axd to a file

This probably has an easy answer, but I haven't been able to find one yet. I was wondering if there was a simple solution to exporting the page-level trace results of trace.axd to a log file of some sort.
Thanks
The <trace> element has a writeToDiagnosticsTrace option, which enables you to capture trace events with a trace listener.
We have done this, but with poor results. Because of incomplete trace support in ASP.NET, we couldn't get anything but the trace event messages into the file - no timestamps, no elapsed time - nothing really useful.
Have a look here it might take you some way to what you want:
http://www.15seconds.com/issue/020910.htm

Why does this code only work when I use a break point?

See code below, for some reason it only works when I put a breakpoint on line 2 (*) is there some delay? Is it starting the next line before it finishes the 2nd one?
dp.SSLCertStoreType = nsoftware.IBizPayPal.DirectpaymentSSLCertStoreTypes.sstPEMKey
*dp.SSLCertStore = My.Computer.FileSystem.ReadAllText(Server.MapPath("\cert_key_pem.txt"))
dp.SSLCertSubject = "*"
Note: The error is thrown on the 3rd line only when the breakpoint is set on the 2nd line, after releasing the break the program executes my paypal purchase via credit card.
I will post the error again I am replicating it now...
System error: Could not acquire security credentials: error 8009030E.
There it is, while it should say "Order Confirmed!" type message if working correctly.
Almost certainly a threading issue, but nobody is going to be able to answer definitively unless they're familiar with nsoftware.IBizPayPal
Sometimes you can find that breaking can mutate an object's state, due to the locals window evaluating object properties. If they have a side-effect, then all bets are off, unfortunately :( No idea whether this is happening in your case.
I have no knowledge of ASP, so just wondering aloud: Could this be due to multithreading? You know when you put a break point you sort of freeze execution of all threads, but not so in the real execution.

Resources