File upload 使用.ashx上载多个文件

File upload 使用.ashx上载多个文件,file-upload,upload,uploadify,swfupload,image-upload,File Upload,Upload,Uploadify,Swfupload,Image Upload,我已经看了好几天了,但都没有成功。我正在尝试创建一个网站的多文件上传系统。我尝试了几个jQuery插件,包括SWFUpload和Uploadify。除了实际上传之外,一切正常;上载的文件从未保存到文件夹中。我猜这就是我使用.ashx的方式,所以对于下面的代码有什么问题,我们非常感谢。谢谢 //Jquery is inherited, and I'm pretty sure this is all correct <link href="/_uploadify/uploadify.css"

我已经看了好几天了,但都没有成功。我正在尝试创建一个网站的多文件上传系统。我尝试了几个jQuery插件,包括SWFUpload和Uploadify。除了实际上传之外,一切正常;上载的文件从未保存到文件夹中。我猜这就是我使用.ashx的方式,所以对于下面的代码有什么问题,我们非常感谢。谢谢

//Jquery is inherited, and I'm pretty sure this is all correct
<link href="/_uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/_uploadify/swfobject.js"></script>
<script type="text/javascript" src="/_uploadify/jquery.uploadify.v2.1.4.min.js"></script>

//Again, this all works as expected.  CSS displays, SWF works, the issue I THINK deals
//with 'script' and 'folder'.  My Upload.ashx is in the root, as well as uploads folder
<script type="text/javascript">
$(document).ready(function () {
    alert("here");
    $('#file_upload').uploadify({
        'uploader': '/_uploadify/uploadify.swf',
        'script': 'Upload.ashx',
        'cancelImg': '/_uploadify/cancel.png',
        'folder': 'uploads',
        'multi': true,
        'auto': true
    });
});
</script>

<input id="file_upload" name="file_upload" type="file" />

//My handler code, I'm not sure if this works or not but I do know that if
//I try to debug nothing ever fires... I'm sure that's part of the problem
<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.IO;

public class Upload : IHttpHandler {

public void ProcessRequest(HttpContext context)
{
    HttpPostedFile file = context.Request.Files["Filedata"];

    file.SaveAs("C:\\" + file.FileName);

    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello World");
}

public bool IsReusable
{
    get
    {
        return false;
    }
}
}
//Jquery是继承的,我很确定这一切都是正确的
//同样,这一切都按预期进行。CSS显示,SWF工作,我认为这个问题很重要
//使用“脚本”和“文件夹”。My Upload.ashx位于根目录中,也位于uploads文件夹中
$(文档).ready(函数(){
警报(“此处”);
$('#文件上传')。上传({
“uploader”:“/_uploadify/uploadify.swf”,
'script':'Upload.ashx',
'cancelImg':'/_uploadify/cancel.png',
'文件夹':'上载',
"多":对,,
“自动”:真
});
});
//我的处理程序代码,我不确定这是否有效,但我知道如果
//我试着调试任何东西都不会触发。。。我相信这是问题的一部分
使用制度;
使用System.Web;
使用System.IO;
公共类上载:IHttpHandler{
公共void ProcessRequest(HttpContext上下文)
{
HttpPostedFile file=context.Request.Files[“Filedata”];
file.SaveAs(“C:\\”+file.FileName);
context.Response.ContentType=“text/plain”;
context.Response.Write(“helloworld”);
}
公共布尔可重用
{
得到
{
返回false;
}
}
}

这就是我所拥有的一切。如果我尝试用SWFUpload jQuery上传一个文件,它会说它成功了,但是没有任何东西保存到文件夹中。如果我尝试使用Uploadify,它会因HTTP错误或IO错误而失败,并且同样,不会保存任何内容。谢谢您的帮助。

经过一段时间的调试,我终于找到了答案。问题实际上与表单身份验证有关,并且发生在登录屏幕之后的任何页面上。这里是修复

将以下代码片段之一添加到web.config

如果您不担心任何身份验证,请尝试

  <authorization>
    <allow users="*"/>
  </authorization>

如果您只想允许访问新的处理程序,请执行以下操作

<location path="_handlers/Upload.ashx">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>
</location>


在我这样做之后,我的处理程序文件中的调试点被击中了,我可以从那里解决其余的问题。

您的ashx文件是在成员区域还是其他地方?这可能是一个会话问题。