0

I am working on a utility that track redirections. HTTP redirections are pretty well handled by the following c# methods:

  • HttpWebRequest
  • HttpWebResponse
  • WebHeaderCollection (Location filed)

Next step is to include javascript redirections in a url journey to the final page.

  1. How can I capture this type of redirection in c#?
  2. Are there any other types of redirection that should be taken into consideration?
6
  • When you say Capture.. are you wanting to store the redirected URL in a List prior to Invoking the redirects..? Commented Jan 11, 2012 at 21:19
  • 1
    "Track redirection" of what - it looks like you want to figure what final page would be if browser would render it without actually using browser? Commented Jan 11, 2012 at 21:25
  • You will need a full blown javascript interpreter to achieve this. Commented Jan 11, 2012 at 21:27
  • Yes. The missing bit is js redirection. I am getting to the point where after few redirections through the Location field in header I am getting status code - OK. I would assume that this is the final page, but then according to the fiddler output there JS redirection of some sort. And this is what I am trying to capture. Commented Jan 11, 2012 at 21:29
  • 1
    I think you have to use an embedded Browser like 'WebBrowser'. / Commented Jan 11, 2012 at 21:32

2 Answers 2

3

If you use an embedded javascript engine and create data models that mock up some of the more commonly accessed aspects of the DOM and the javascript apis/prototypes, then you could load the page, execute any and all javascript code and have your window.location property setter fire an event when it gets set, then just follow that url as normal. This allows you to handle computed values as well as your standard

window.location = "/home";

There are no short supply of embedded javascript engines for C#, here are just a few that I find to be really good:

Javascript.Net - Uses Google's V8 engine. Really easy to integrate in an application. Only downside-ish is keeping an unmanaged DLL with your application. https://github.com/JavascriptNet/Javascript.Net

Jint (Javascript Interpreter for .Net) - Really good. Fully managed code. Again, easy to integrate within an application. http://jint.codeplex.com/

The real key here is mocking up what is normally created by a browser.

Sign up to request clarification or add additional context in comments.

Comments

0

Your only practical option is to use full blown browser to do that. You can either use WebBrowser control for WebForms, or automation of browser (directly for IE, or through something like Selenium or WebAII), or embedding other browser engine (I think WebKit have C# bindings...). Using full blown browser engine will also take care of other redirection mechanisms whatever are there.

Alternative would be to implement at least partial HTML DOM and JavaScript engine which is definitely interesting project...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.