asp.net防止上传木马图片的问题 怎样才能有效防止呢?判断后缀名显然只是最简陋的一种方法,还需要判断Js vbs html...?求终极方案,有代码的贴上来共享一下!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 fileupload 判断图片格式 this.FileUpload1.PostedFile.ContentType 我看帖后google了一下,据说图片木马不影响图片的格式` http://www.cnblogs.com/jueban/archive/2009/03/06/933121.html http://topic.csdn.net/u/20090414/14/241c481a-f398-48cd-bde8-296510c38092.html 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; } } 如果读取文件的MIME类型不行的话,真想不出来哪个是可行的 LZ试验ContentType 将读取结果输出一下看看就明白了。 <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.csusing System.Web;public class FakeHttpHandler : IHttpHandler{ public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { context.Response.Write("not allowed"); }} 三层分页? 为什么网站同时访问人数一多网速就会超级慢? Asp.net MVC 开发的demo项目截图,哈哈 IIS6经常莫名其妙停止响应!求助 怎样把别人网站的某部分新闻抓到自己网站上显示? 搜狐网站中的在线视频功能,在asp.net下如何实现?提供思路也可。 用Asp.net和SQL开发了一个系统但不知道怎么打包成安装文件。。 绑定datagrid,怎么做横向汇总,请各位帮忙!谢谢 关于开启项目错误 征集.net开发的商城源码 新手求助!怎么实现这个?????? gridview中单击某行按钮如何得到当前行的textbox中的值
this.FileUpload1.PostedFile.ContentType
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;
} }
将读取结果输出一下看看就明白了。
<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");
}
}