0

Is there a way for a standard C# desktop app to detect the URL that the browser is going to navigate to, and possibly prevent it from doing that? An example would be all those download managers that pop up when I click a link in the browser and prevent browser's default action from occurring.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
dotNET
  • 33,414
  • 24
  • 162
  • 251
  • Do you mean for example I have Firefox browser. I want to monitor all the links entered by the user in the address bar? – Jobert Enamno Jan 16 '13 at 05:45
  • Yes and no. I don't want to maintain or retrieve the list of all the addresses entered by the user. All I want is to get my applicaton notified when user tries to access a URL in a browser. Upon detecting such activity, my application should intervene and do a specific action with that URL and just cancel browser's default action that it was going to perform (e.g. download the link or simply navigate to it etc.) – dotNET Jan 16 '13 at 05:52
  • 1
    Is this the one you want : http://stackoverflow.com/questions/1420931/how-to-block-a-website-programatically-using-dotnet – Srinivas Jan 16 '13 at 06:06
  • 1
    this cannot be done by C# and Browser alone since a Browser is a separate application and there's no way to invade its privacy or even control it from C# codes. What you need is a C# application that communicates with your network thus to monitor the logs from your network. This involves networking skills as you have to get all of your outgoing url request from the network. – Jobert Enamno Jan 16 '13 at 06:20
  • 1
    This may help.. http://stackoverflow.com/questions/3579649/get-url-from-browser-to-c-sharp-application – C-va Jan 16 '13 at 06:30
  • @JobertEnamno: I know this can be done. Try downloading FDM (or similar download manager apps) and see how they sniff into your browser's activities and whenever u click a link that is going to download a file, they "invade the privacy" of your browser, block it from downloading the file and instead present their own UI for the same purpose. – dotNET Jan 16 '13 at 06:30
  • @Srinivas: Thanks, but that guys seems to be doing it from within his own application. I'm doing this at a different level; a system-wide monitoring agent that detects download activity in any browser. Think of download managers. – dotNET Jan 16 '13 at 06:31
  • @MSK: Thanks. That is one good starting point. Two apparent issues I can see: One is that I'll need to continue polling all open windows for url change detection, instead of getting "notified" about such an activity. Secondly, the link doesn't talk about cancelling browser's native action. – dotNET Jan 16 '13 at 06:38
  • 1
    From an external application, here is a link that could help: http://stackoverflow.com/questions/5317642/retrieve-current-url-from-c-sharp-windows-form/5318791#5318791 Otherwise, you will need to develop an addin for each browser (that talks to an external app possibly), for example in IE, that could be a BHO http://en.wikipedia.org/wiki/Browser_Helper_Object – Simon Mourier Jan 16 '13 at 07:28
  • @SimonMourier: Thanks. That was my finding as well that I'll need to write one plug-in for each browser. – dotNET Jan 16 '13 at 07:55
  • @Dan-o: Does fiddler core allow me to control browser's response too? Or does it only sniff on tcp channel? – dotNET Jan 16 '13 at 07:56
  • FDM uses it's add-on application installed on the browser that's why it can detect the download links – Jobert Enamno Jan 16 '13 at 11:54
  • Read the FiddlerCore docs. It's an HTTP proxy. You can do anything with it that a proxy can do. – Sam Axe Jan 16 '13 at 21:11

1 Answers1

3

you can not access to internet browsers from winform projects but you can access if you have a plug-in app. for browsers. Develop a plug-in app. and communicate with your winform app. like internet download manager app. here is expamle for IE add-ons IE add-on express for chrome Google dev guide

hopefully helps it.

Lütfullah Kus
  • 302
  • 1
  • 12
  • Thanks man. That's a whole lot of help. I also found out that the only way to do it is to write one plug-in for each browser. – dotNET Jan 16 '13 at 07:58