473,509 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

uploading / downloading protected files in ASP.NET

I have a web application where the admin wants to be able to upload
arbitrary files on an admin page... and then have them accessible for
certain users. Easy enough eh?

The difficulty I'm having is serving up these files in a secure AND
browser-friendly way. I'm using Form authentication. I can't just
drop them in a website directory and show links to the files, because
then anyone could get at a file whose extension is not explicitly
protected by ASP.NET.

So... the option I came up with was to write a proxy page which just
uses Response.WriteFile() after some security checks. Well, that
works fine, but then the URL ends up being something like:

http://mysite.com/getfile?filename=file.doc

...and then of course the browser just dumps the raw bytes of the file,
it doesn't know that this is a .doc file its receiving like if the URL
had been http://mysidte.com/files/file.doc.

Any way to fix this? Do I send down a MIME-type header? If so, where
do I get that? Because the admin could upload any sort of document...
all I have is the file name, more or less. Is there any way to tell
IIS to handle ALL file types for a particular directory? That way
Forms authentication could protect everything?
Any suggestsions greatly appreciated.

Jun 21 '07 #1
3 1389
Hi,

br******@hotmail.com wrote:
I have a web application where the admin wants to be able to upload
arbitrary files on an admin page... and then have them accessible for
certain users. Easy enough eh?

The difficulty I'm having is serving up these files in a secure AND
browser-friendly way. I'm using Form authentication. I can't just
drop them in a website directory and show links to the files, because
then anyone could get at a file whose extension is not explicitly
protected by ASP.NET.

So... the option I came up with was to write a proxy page which just
uses Response.WriteFile() after some security checks. Well, that
works fine, but then the URL ends up being something like:

http://mysite.com/getfile?filename=file.doc
That sounds like a good idea.
..and then of course the browser just dumps the raw bytes of the file,
it doesn't know that this is a .doc file its receiving like if the URL
had been http://mysidte.com/files/file.doc.
Actually, even when the browser receives a file.doc file, it doesn't
know what file it is. You are right that you must send a MIME type. The
MIME type is sent by IIS when you link to a DOC file directly. According
to the MIME type, the browser will decide what action he will use,
according to the user settings.

MIME type is set in the Response.ContentType property.
http://msdn2.microsoft.com/en-us/library/ms525208.aspx
Any way to fix this? Do I send down a MIME-type header? If so, where
do I get that? Because the admin could upload any sort of document...
all I have is the file name, more or less. Is there any way to tell
IIS to handle ALL file types for a particular directory? That way
Forms authentication could protect everything?
The MIME type cannot, as far as I know, be generated automatically. You
will need to create a table extension --MIME type. Of course, it would
be a good idea to make this table a XML file (config file, or simply
external XML file) so that you or your user can dynamically add new
extensions/MIME type mapping information.

Any suggestsions greatly appreciated.
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 21 '07 #2
Well, ya learn something new every day... Not sure how I went this
long without realizing this. I also see that the HttpPostedFile
object has a ContentType property. So I can alternatively just save
that and push the same string back down when the file is downloaded.

Thanks for the help.

Jun 21 '07 #3
Lit
I save my file info to a database table along with the ContentType...
including the content.
that could eliminate or work the security concerns you have also.

Just an idea....


<br******@hotmail.comwrote in message
news:11*********************@g37g2000prf.googlegro ups.com...
Well, ya learn something new every day... Not sure how I went this
long without realizing this. I also see that the HttpPostedFile
object has a ContentType property. So I can alternatively just save
that and push the same string back down when the file is downloaded.

Thanks for the help.

Jun 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1824
by: Asha | last post by:
greetings, i need to upload an .xls file using a secure connection. so i though of using https... can i know how this can be done?
2
1255
by: D. Shane Fowlkes | last post by:
I'm about to build in some functionality where my client's staff can do some kind of basic upload to a folder or series of folders on our web server and allow authenticated users to know the UID...
1
1156
by: Garett Rogers | last post by:
I am creating a document manager for our intranet in VB.NET and I have stumbled across a problem that I cant seem to find a solution for. Everything is working as planned: 1) upload a file from...
0
1504
by: TJ | last post by:
Hi, I've written code web-based uploading and downloading. Here is some code for it. For saving file into MS-SQL database, SaveFileIntoDB(HttpPostedFile file) { int fileLength =...
4
2141
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
3
1626
by: OriginalBrownster | last post by:
I am currently uploading a file from a users computer to the file system on my server using python, just reading the file and writing the binaries. total_data=' ' while True: data =...
0
1208
by: mivey4 | last post by:
I have been experimenting with sending and receiving files using the webClient class provided in .NET. (C#) I don't seem to have any problems downloading files from my test web server using the...
221
366982
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
3
5159
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.