Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please provife me the code and file in asp.net,

how to prevent of uploading renamed .exe file in asp.net
Posted

You have to look in the binary file itself. There are many approaches. See some interesting ones here: http://stackoverflow.com/questions/2863683/how-to-find-if-a-file-is-an-exe[^] (except the one that is suggesting you to start it :), since that is a really bad idea)
 
Share this answer
 
v2
If you mean "how do I prevent the user from uploading the same file under a different name?", then the easiest way if to keep a hash value of each file with the file itself: for this application an MD5 should be fine (since this isn't secure information and MD5 is a lot shorter than the alternatives) or you could use an SHA hash, but they are longer, and slower to generate.
When the user uploads a file, you calculate the hash value and compare it against your database of existing files hash values. If you get a match, you can (optionally) compare the actual file data. If you don't, then the file does not exist under any file name.

MSDN and Google can help you with generating the hash value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900