如何防止在asp.net中上传重命名的.exe文件 [英] how to prevent of uploading renamed .exe file in asp.net

查看:107
本文介绍了如何防止在asp.net中上传重命名的.exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我asp.net中的代码和文件,



如何防止在asp.net中上传重命名的.exe文件

Please provife me the code and file in asp.net,

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

推荐答案

你必须查看二进制文件本身。有很多方法。在这里查看一些有趣的内容: http://stackoverflow.com/ question / 2863683 / how-to-find-if-a-file-is-an-exe [ ^ ](建议你启动它的那个:),因为这是一个非常糟糕的主意)
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)


如果您的意思是我如何阻止用户以不同的名称上传相同的文件?,那么最简单的方法是将每个文件的哈希值与文件保持一致本身:对于这个应用程序,MD5应该没问题(因为这不是安全信息,MD5比备选方案短很多),或者你可以使用SHA哈希,但它们更长,生成速度更慢。

当用户上传文件时,您计算哈希值并将其与现有文件哈希值的数据库进行比较。如果匹配,您可以(可选)比较实际文件数据。如果不这样做,那么该文件在任何文件名下都不存在。



MSDN和Google可以帮助您生成哈希值。
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.


这篇关于如何防止在asp.net中上传重命名的.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆