I am working on asp.net with c#.
There is a file upload control in my form. Everything is working fine.
The problem is that an .exe
file can be uploaded by just renaming it. I would also like to restrict the size.
I am working on asp.net with c#.
There is a file upload control in my form. Everything is working fine.
The problem is that an .exe
file can be uploaded by just renaming it. I would also like to restrict the size.
best way in your case is check the first bytes of the file to determine what they are.
you should use FindMimeFromData function to determines the MIME type from the data provided.
Have a look at this file signatures table
and at this SO answer that shows you how get mime type without using extension.
Here there is a table with List of file signatures
exe
files have hex signature4D 5A
(In ASCII representation,0x5A4D
isMZ
)from this point we can do this function