首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

[讨论]在asp.net2.0验证上传文件格式的各种方法解决办法

2011-12-30 
[讨论]在asp.net2.0验证上传文件格式的各种方法一、通过扩展名好处是简单易用,服务器负载低(可以用验证控件

[讨论]在asp.net2.0验证上传文件格式的各种方法
一、通过扩展名
        好处是简单易用,服务器负载低(可以用验证控件在客户端验证)
        但是安全性差,不能防止改恶意文件的扩展名上传


二、if(   FileUpload.PostFile.CommentType   =   "image/jpeg "   )
        不知道效率和安全性如何,没用过


三、System.IO.FileStream   fs   =   new   System.IO.FileStream(File,   System.IO.FileMode.Open,   System.IO.FileAccess.Read);
                System.IO.BinaryReader   br   =   new   System.IO.BinaryReader(fs);
           
                string   fileClass   =   br.ReadByte().ToString()   +   br.ReadByte().ToString();

                fs.Close();
                br.Close();

                if   (fileclass   ==   "255216 "   ||   fileclass   ==   "7173 "   ||   fileclass   ==   "6677 "   ||   fileclass   ==   "13780 ")//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
                {
                        return   true;
                }
                else
                {
                        return   false;
                }
       
似乎最安全,可是文件流和二进制流的使用会不会让服务器负载很大呢?


大家根据经验谈谈体会吧~~~

[解决办法]
沙发,而且关注

热点排行