Question

I have set up a URL redirect on http://freedns.afraid.org/ so I can change host to a file that my application downloads, without the need of changing the code in my app.

The problem is that I need to resolve the correct URL before downloading the file. I tried a method I found here at SO but it didn't work (Webrequest).

So I suppose that they don't use a common redirect.

How can you resolve the real url/ip?

UPDATE:

I have another subdomain over at freedns, and if you do a downloadstring on that one you get the page that it should redirect to. Maybe that info can be to any help.

UPDATE2:

Here is the code I use to fetch the other webpage:

        WebClient client = new WebClient();
        string xml = client.DownloadString(new Uri("myfreednshere"));

So by running that code, I get the string of the webpage b, that the "myfreednshere" redirects to.

Which means that the webclient succeeds in resolving the url redirect. Is there any code that I can use that just resolves the redirect?

UPDATE3:

This is the response I get with a httprequest:

{X-Abuse: URL redirection provided by freedns.afraid.org - please report any misuse of this service
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Cache-Control: public, max-age=15
Content-Type: text/html
Date: Wed, 09 Nov 2011 21:55:21 GMT
Server: Apache/1.3.41 (Unix) PHP/5.3.6 with Suhosin-Patch
X-Powered-By: PHP/5.3.6

}
Was it helpful?

Solution

I've noticed that at least one afraid.org site (http://fb.afraid.org, the only domain I could get to work with a quick check) does not use HTTP redirection, 301 redirects, or proxying. It uses frames. So, your original code should work:

    WebClient client = new WebClient();
    string xml = client.DownloadString(new Uri("myfreednshere"));

With a little modification, I used this code:

    WebClient client = new WebClient();
    string html = client.DownloadString(new Uri("http://fb.afraid.org"));

the result of the call had the real url (http://www.fragbite.com) in three places, once in a comment, once in a frame source, and once in a link in the noframes tag. You should be able to parse the url out if you need it programatically.

OTHER TIPS

the WebClient class follows redirects. Try using HttpWebRequest:

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.AllowAutoRedirect = false;

After the request is made, one of the HTTP headers "Location", gives the location where it was redirected to (but didn't follow because AllowAutoRedirect was off)

So you're wanting a 301 Redirect?

It can be handled a couple of ways. If this is .NET, and if you're using IIS 7, you can use the URL Rewrite module (http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/), or you may be able to modify the web.config file directly if you know what you're doing.

    <system.webServer>
  <httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" />
</system.webServer>

Follow this link for more info on how to handle 301's http://knowledge.freshpromo.ca/seo-tools/301-redirect.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top