我正在尝试使用Asp.net + Jquery创建带有进度条的文件上传器。
重要的是我没有MVC网页。
我已按照此处的说明操作: http://blog.stevensanderson.com/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/
然而,它只是跳过我需要创建的整个处理程序..
到目前为止,我有:<script src="../../Scripts/swfupload.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-asyncUpload-0.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#yourID").makeAsyncUploader({
upload_url: "/Controls/UploadHandler.ashx", // Important! This isn't a directory, it's a HANDLER such as an ASP.NET MVC action method, or a PHP file, or a Classic ASP file, or an ASP.NET .ASHX handler. The handler should save the file to disk (or database).
flash_url: '../../Scripts/swfupload.swf',
button_image_url: '../../Scripts/blankButton.png'
});
});
</script>
并且一切正常。但是它显然没有上传,因为我没有处理程序..但我不知道从哪里开始使用ASHX处理程序..
我尝试过在网上搜索失败。有人能指出我正确的方向如何创建这个处理程序?
答案 0 :(得分:0)
我对它进行了分类
<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.Web;
using System.IO;
public class UploadHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string strFileName = Path.GetFileName(context.Request.Files[0].FileName);
string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();
string strLocation = context.Server.MapPath("~/SaveFile") + "/" + strFileName;
context.Request.Files[0].SaveAs(strLocation);
context.Response.ContentType = "text/plain";
context.Response.Write("OK");
}
public bool IsReusable {
get {
return false;
}
}
}