Response.WriteFile() Doesn't Trigger Download Managers

K

Khafancoder

Hi guys,

i am building a FileSharing website,
i wanna allow users to be able using download managers such as DAP to
download files from webserver but
don't allow them to retrive files url...
so i used Response.WriteFile but it won't trigger any download manager
such as DAP or FlashGet

i used this code :


Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=MyFile.zip");
Response.AddHeader("Accept-Ranges", "bytes");
Response.AddHeader("Etag", "\"90a94a56b3bcc71:bea\"");
Response.WriteFile(file_path);
Response.End();

Thanks In Advance
 
J

Jesse Houwing

Hello Khafancoder,
Hi guys,

i am building a FileSharing website,
i wanna allow users to be able using download managers such as DAP to
download files from webserver but
don't allow them to retrive files url...
so i used Response.WriteFile but it won't trigger any download manager
such as DAP or FlashGet
i used this code :

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=MyFile.zip");
Response.AddHeader("Accept-Ranges", "bytes");
Response.AddHeader("Etag", "\"90a94a56b3bcc71:bea\"");
Response.WriteFile(file_path);
Response.End();
Thanks In Advance

Usually these download managers don't work if the download originates from
a postback. Make sure you're using a normal link to the download page. And
that the download page immediately presents the user with the requested download
based on the query string information.
 
K

Khafancoder

Thanks Jesse,

here is what exatcly happening :

my client wants to redirect all users to his domain for downloading
any file from his website...
(in fact he don't want that users be able to download his files from
links which placed in other sites or forums directly)
so we decide to make downloads available by clicking on a button in a
special page (such as RapidShare)
but he also wants his users could use download managers...

Thanks
 
J

Jesse Houwing

Hello Khafancoder,
Thanks Jesse,

here is what exatcly happening :

my client wants to redirect all users to his domain for downloading
any file from his website...
(in fact he don't want that users be able to download his files from
links which placed in other sites or forums directly)
so we decide to make downloads available by clicking on a button in a
special page (such as RapidShare)
but he also wants his users could use download managers...
Thanks

you'd have to make a 2-step download. On the landing page (the one with the
busson) set a flag in the session or set a cookie. Then do a response.redirect
to the download page, passing the query string parameters again. On the download
page check if the session variables or the required cookie is there. If it
is, proceed with the download. If it's not server.transfer back to the landing
page.

Jesse
 
J

Jesse Houwing

Hello Khafancoder,
Thank you for reply,

a postback.

i think because it's a POST request, right ?

so,i change it to a GET request by calling download function in
Page_Load...

but sometimes it trigger download manager and sometimes it doesn't (on
IE), and in firefox download manager never triggered !

of course when i make request to a physical file, in both of them (IE
& FF) DAP will handle the downloads.

so i monitor HttpHeaders diffrence between these requests ("my GET
request" and "calling file directly") and both of them send the same
request to IIS

and finally ! yes i forget something ! it's because of the .aspx
extension !!! DAP won't handle this extension.

so i used your solution (two pages for downloads) and paste the
extension of requested file -as a querystring parameter- to url of
second page, and it works !

Thank you so much Jesse

i used this code :

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=MyFile.zip");
Response.AddHeader("Accept-Ranges", "bytes");
Response.WriteFile(path);
Response.End();


You're welcome :)
 
K

Khafancoder

Thank you for reply,
a postback.

i think because it's a POST request, right ?

so,i change it to a GET request by calling download function in
Page_Load...

but sometimes it trigger download manager and sometimes it doesn't (on
IE), and in firefox download manager never triggered !

of course when i make request to a physical file, in both of them (IE
& FF) DAP will handle the downloads.

so i monitor HttpHeaders diffrence between these requests ("my GET
request" and "calling file directly") and both of them send the same
request to IIS

and finally ! yes i forget something ! it's because of the .aspx
extension !!! DAP won't handle this extension.

so i used your solution (two pages for downloads) and paste the
extension of requested file -as a querystring parameter- to url of
second page, and it works !

Thank you so much Jesse


i used this code :


Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=MyFile.zip");
Response.AddHeader("Accept-Ranges", "bytes");

Response.WriteFile(path);
Response.End();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top