user1211929
user1211929

Reputation: 1190

Monitor web pages access

I hope I can get some help. I’m trying to create an host based application using C# (in the simplest way) to monitor access to a web page from the computer that hosts the application, if this web page is accessed while the program is running an event should rise. So far I have used the SHDocVw.ShellWindows() but it works only if the web page has already been accessed not while is being accessed. It monitors Windows Internet Explorer

I have also researched the httplistener but to no avail.

Do you have any solution? Please let me know if you require more details

Upvotes: 3

Views: 2045

Answers (3)

user1211929
user1211929

Reputation: 1190

After few hours of work I have found a solution, not the most elegant one so far,(and at times causes a memory dump) but it does what I need. Thanks

Just last edit, I solved the crash issue by adding a time so it checks the page every sec or so. once again thanks for your iterest in my question.

class wait
{

    private static System.Timers.Timer aTimer;
   public  void timed1()
    {

        // Create a timer with a ten second interval.
        aTimer = new System.Timers.Timer(10000);

        // Hook up the Elapsed event for the timer.
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

        // Set the Interval to 2 seconds (2000 milliseconds).
        aTimer.Interval = 2000;
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program.");
        Console.ReadLine();


    }


    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {

        //NetKeyLogger klog = new NetKeyLogger();
        // Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
        Kelloggs.Program KKA = new Kelloggs.Program();


        SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
        string filename;

        foreach (SHDocVw.InternetExplorer ie in shellWindows)
        {
            filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
            if (filename.Equals("iexplore"))
            {

                string ddd = (ie.LocationURL);
                // Console.WriteLine(ddd);

                if (ie.LocationURL == "http://www.testPage.com/")
                {
                    Console.WriteLine("Page found");
                    // Console.ReadLine();
                    aTimer.Enabled = false;
                    KKA.Maino();

                }
            }

Upvotes: 2

Alexei Levenkov
Alexei Levenkov

Reputation: 100527

Assuming the question is "I want to know when a program on my local computer accesses a give web page": A transparent http proxy is likely approach you want to take. Check out Fiddler to see if it is exactly what you want.

If your question is more "I want to know when a particular page is hit on my remote server": There are plenty of monitoring tools that parse web server logs and event logs to know state of the server. If you want to do something yourself and control the server's code - collect hit information for the page you are interested and provide some page that reports this data.

Upvotes: 2

M.Babcock
M.Babcock

Reputation: 18965

This may or may not be valid for your situation, but I had to do something similar with an Intranet website (cross-browser so it was a little harder than just with IE) recently. My solution was to setup a client-side application which hosts a WCF service. Then, when the user clicks a link on the web page (or raises any event, such as, $(document).ready) it sends an message back to the server telling the server to connect to the IP address associated with the current session (really just the IP Address on the request) on a known port. This connection is made to the client side application which is listening at that IP address and port for instructions on what to do (in my case it is dynamically compiling code in the request and running it).

That of course will only work for Intranet websites. A more general approach that will work for IE across the internet, is to create a IE extension (or maybe a Silverlight application) that talks on localhost. I've never done it, so I can't tell you how or if it is actually possible (but in principle seems possible).

If you don't have access to the website at all then perhaps using SharpPCAP or the Fiddler API would work for you.

Upvotes: 2

Related Questions