怎样才能有效防止呢?
判断后缀名显然只是最简陋的一种方法,还需要判断Js vbs html...?
求终极方案,有代码的贴上来共享一下!!

解决方案 »

  1.   

    fileupload  判断图片格式 
     this.FileUpload1.PostedFile.ContentType
      

  2.   

    我看帖后google了一下,据说图片木马不影响图片的格式`
      

  3.   

    http://www.cnblogs.com/jueban/archive/2009/03/06/933121.html
      

  4.   

    http://topic.csdn.net/u/20090414/14/241c481a-f398-48cd-bde8-296510c38092.html
      

  5.   


    public static bool ChkType(FileUpload hifile)
        {
            System.IO.FileStream fs = new System.IO.FileStream(hifile.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
            string fileclass = "";
            byte buffer;
            try
            {
                buffer = r.ReadByte();
                fileclass = buffer.ToString();
                buffer = r.ReadByte();
                fileclass += buffer.ToString();
            }
            catch
            {        }
            r.Close();
            fs.Close();
            if (fileclass == "255216" || fileclass == "7173")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
            {
                return true;
            }
            else
            {
                return false;
            }    }
      

  6.   

    如果读取文件的MIME类型不行的话,真想不出来哪个是可行的
      

  7.   

    LZ试验ContentType 
    将读取结果输出一下看看就明白了。
      

  8.   

    <configuration>
        <system.web>
            <httpHandlers>
                <add verb="GET,POST" path="*.aspx" type="FakeHttpHandler"/>
                <add verb="GET,POST" path="*.asp" type="FakeHttpHandler"/>
            </httpHandlers>
        </system.web>
    </configuration>
    在 app_code 目录下添加 FakeHttpHandler.cs
    using System.Web;
    public class FakeHttpHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }    public void ProcessRequest(HttpContext context)
        {
            context.Response.Write("not allowed");
        }
    }