0

I have the following code in my page:

if (Request.QueryString("link_id") == "12345" )
{
    Responce.Redirect("http://www.downloadsite.com/blablabla.png");
}

Now I want to hide that URL when somebody adds this link to his internet download manager :

http://www.mysite.com?link_id=12345

as you see the goal domain in different, I just want prevent my users to share my links.

Thanks in advance.

Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
SilverLight
  • 19,668
  • 65
  • 192
  • 300

1 Answers1

2

If I understand the question, you're trying to let the user download a file from http://www.downloadsite.com/blablabla.png that appears to the user, in every sense, to be coming from http://www.mysite.com?link_id=12345. This is what I'd try:

if (Request.Params["link_id"] == "12345")
{
    Uri uri = new Uri("http://www.downloadsite.com/blablabla.png");
    using (var wc = new WebClient())
    using (var download = wc.OpenRead(uri))
    using (var respStream = Response.OutputStream)
        download.CopyTo(respStream);
}
Tim S.
  • 55,448
  • 7
  • 96
  • 122
  • really thanks for the answer / but that download pop-up does not come up...what is wrong? – SilverLight Jun 16 '13 at 18:20
  • i am so sorry for my dely, would you please consider to my prev comment! – SilverLight Jun 16 '13 at 18:32
  • You might be looking to set the `content-disposition` to `attachment`, to tell the browser it should download the content, instead of trying to display it inline. http://stackoverflow.com/questions/1012437/uses-of-content-disposition-in-an-http-response-header You might also want to make sure the MIME type (Content-Type) and any other metadata is set correctly. To see metadata from the original URL, see http://stackoverflow.com/questions/4423061/view-http-headers-in-google-chrome or search for "see http headers". – Tim S. Jun 16 '13 at 19:04
  • i have many .mkv (movies) next blablabla.png / did your solution work for thsoe files? – SilverLight Jun 16 '13 at 19:14
  • Yep, it should work for any file type; the only thing that'll be different is the source URL and, if you specify it, the Content-Type. – Tim S. Jun 16 '13 at 19:16
  • would you please complete your answer for a mkv file, i do n't want that file to be downloaded on my server... – SilverLight Jun 16 '13 at 19:18