this is my situation:
I need to create an app that listens to URL's entered on a browser so that when a particular site is entered (e.g. google.com), it redirects this to www.mysite.com/Redirect.aspx?site=google.com, so that this click is recorded on mysite.com and then the user is redirected to the original entry i.e. google.com
One idea I had was to create an app on Windows that edits the Hosts file. So what I did was, added an entry for google.com, redirecting it 1.2.3.4 (IP of my server), so that the click can be recorded there and the user can be redirected back to google.com
However the problem with this is that, since Hosts redirects any request fo开发者_如何学JAVAr google.com to 1.2.3.4, this whole redirect sequence would be going round in a loop since 1.2.3.4 would lead it to google.com as well.
Could anyone please suggest what I could do to get around this or a better solution?
What I want is similar to parental control software i.e. when a certain website is visited, e.g. www.porn.com, it recognises this address and leads the user to a different site.
The sequence of actions would be :
User enters google.com -> Redirect to mysite.com?Redirect.aspx?site=google.com (record entry on my server) -> go to google.com
What I reckon you want to do is set up a proxy and force all web traffic to go through it. Depending on your situation (whether you need to ensure people use it or if its opt in for whatever reason). Then in your proxy you do the listening and then do your magic redirecting. Depending on what mysite.com does (does it just redirect or will it return the google page?) you may want to either keep state (remember that you just did this redirect so you don't get stuck in a loop) or just fire off a separate request to mysite.com while proxying google.com. This should log the request still while forwarding on your request as desired.
The scope of creating a proxy is a bit big for this question so I'll leave you to go research that yourself.
You can be a proxy (http or socks). This way you will see all requests to all sites and have an option of tracking particular ones. At the same time, user will never notice any redirects in his browser
精彩评论