Tag Archive: C#


I’ve always wanted to experiment with creating “sessions” on websites to mimic real users browsing and using a site, and I’ve finally gotten around to a project that involves this: my goal is to “wrap” an online database that is queried through a series of HTML forms, returns a map, and then allows you to open a popup with an HTML table outlining all the points displayed on the map. A formidable challenge, indeed, but in the awesome language of C#, no big deal.

To successfully establish a user session with a website, you must preserve the correct authentication and session cookies. The web database was built using ASP.NET, so I needed to make sure that I had an ASP.NET Session ID. One of the best ways to find out where cookies are sent to you is using an HTTP proxy to analyze requests and responses. The program of choice is called Fiddler, developed by Microsoft. (You can get the latest version at http://fiddler2.com/.) Unfortunately, I was forced to use Firefox to track packets because the old (straight out of 1997) interface  recognizes the new and revolutionary browser Google Chrome as being Safari 1.3 (how sad), and doesn’t allow you to use their database. and you must set special proxy settings in Firefox for Fiddler to function correctly. After visiting the site and filling out the series of HTML forms, I could see how the report page was functioning – it was using the ASP.NET Session ID along with referrer HTTP header attributes to  find the parameters of my original query and retrieve information from the database.

That might sound like an easy interface to hack, but the cookies are deceptive as you don’t exactly know when they are set. Fortunately, after scouring the internet for an hour or so, I happened to find out about the CookieContainer datatype (HttpWebRequest.CookieContainer). All you have to do to create a cookie “jar” that carries over from one HTTP session to another is writing the following code:

CookieContainer cookieJar = new CookieContainer();
var request=(HttpWebRequest) WebRequest.Create("http://google.com");
request.CookieContainer = cookieJar;

Now you can access the cookies by looping through the CookieContainer in a simple foreach statement. To apply this cookie container to your next HttpWebRequest, all you have to do is:

 request.CookieContainer = cookieJar; 

Yay!

If you’re a .NET developer, admit it: you’ve at least once felt curious about how the underlying APIs behind the .NET Framework are coded, how certain functions are implemented, or whether one core function is more efficient that another. Well, this is where the trusty program named .NET Reflector comes in. As the title suggests, Reflector uses .NET reflection and ILDASM processing. It is the decompiler of the .NET world, and allows you to view source code of DLLs or executables in multiple languages (including C#, VB, C++, Delphi, IL, and more) with ease. It is very interesting to examine how the brilliant programmers at Microsoft sculpted the inner workings of the programming framework that drives many applications today. With this tool, you can accomplish just that and much much more. The Reflector was originally created by Lutz Roeder, but has been acquired by Red Gate Software. The program is free for all to download and use, and it can even Reflect upon itself! Now that is true irony. You can snag a copy over at the Red Gate site.

ThinkGeek has updated the warfare category of their catalog with a new USB-powered missile launcher. Its perks: it has a built-in laser to guide the missiles, it has a very powerful software frontend, and most importantly, it offers an API!!! Finally, developers can terrorize others by coding applications that make use of the firing capibilties of the launcher. The API is built in .NET, so using it is a blast – a sample application is included, complete with raw C# code. And just because of said API, I am willing to slop down 40 bucks for this widget. You can find out more about the product and download the API for free on the product page.  It’ll be interesting to run the DLL through .NET Reflector, and if I find anything intriguing about the way it’s built, I’ll post it here. Have fun terrorizing people! :)

Copyright © 2010 Maxim Zaslavsky. All Rights Reserved.

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin