i want to know that from which pages my current page has been called in ASP.net

As for example

I want the track of page named "hero.aspx" and it has been called from "Zero.aspx"
and "Zero.aspx" has been called from "one.aspx"

So i want output as whole page called hierarchy.

How can i get this in asp.net

Recommended Answers

All 6 Replies

You can use the following code to display the stack trace:

StackTrace ObjStackTrace = new StackTrace();
        StackFrame[] ObjStackFrameArray = ObjStackTrace.GetFrames();

        foreach (StackFrame stackFrame in ObjStackFrameArray)
        {
            Response.Write(stackFrame.GetMethod().Name);
            Response.Write("<br><br>");
        }

I'm not sure if the stack trace is really what you are looking for here. While I have not heard of or used anything such tool in asp.net, a suggestion, or idea for a method comes to mind:

Set a session variable in your global.asax on session start that is a list of strings or something the like. Each time a page is loaded, add a new item to the list containing the name of the page being loaded.

It may be a bit more code than you were hoping to use, but it should do the trick.

Hope that helps.

Hey Knvn, StackTrace class belongs to which namespace??

StackTrace and StackFrame belongs to System.Diagnostics namespace.

TIP: You can get the namespaces from MSDN

I have not heard of or used anything such tool in asp.net, a suggestion, or idea for a method comes to mind

Why cant we use the tool or libraries?, if it is working fine and satisfies our needs.

Set a session variable in your global.asax on session start that is a list of strings or something the like. Each time a page is loaded, add a new item to the list containing the name of the page being loaded.

I don't think there is any performance advantage to track the method caller like this. If I'm wrong, please advise me.

i want to know that from which pages my current page has been called in ASP.net

As for example

I want the track of page named "hero.aspx" and it has been called from "Zero.aspx"
and "Zero.aspx" has been called from "one.aspx"

So i want output as whole page called hierarchy.

How can i get this in asp.net

Have a look at these tutorials:

1. Page Tracking in ASP.NET
2. Implement Web form tracking with ASP.NET

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.