asp.net中的ashx页无法读取上传的文件
a.ascx页面通过Jquery的Ajax异步上传文件,转到b.ashx页处理。所有参数都能a.ashx页获取,但就是无法读取到文件。
a.ascx的相关代码如下:
function PostImage() { $.post("../../../AjaxResponse/Handler.ashx?time=" + Math.random(), { imgPath: $("#imgFileUpload").val(), action: "checkSize", filepath: "temp", maxSize: "5000" }, function (data) { $("#imgPreview").attr("src", data.toString()); //显示缩略图 }); }public class TypeEditCoverHandler : IHttpHandler{ //获取栏目类别的封面图片 public void ProcessRequest(HttpContext context) { //context.Request.ContentType = "multipart/form-data"; context.Response.ContentType = "text/plain"; //获取页面传过来的状态 string strState = context.Request["action"]; //获取文件大小限制 int maxSize = Moore.Help.DataConverter.StrToInt(context.Request["maxSize"]); //获取文件路径 string strImgPath = context.Request["imgPath"]; //能正确读到:D:\图片上传测试\04.jpg HttpPostedFile imgPostFile = context.Request.Files[strImgPath]; //一直为null //临时文件名称 string strTempImageName = String.Empty; …… 后面的略
get {
return false;
}
}
}
jquery.form.js下载地址
http://malsup.github.com/jquery.form.js