Reputation: 808
I have been looking at this for several days now with no success. I am trying to create a multi-file upload system for a website. I have tried several jQuery plugins, including SWFUpload and Uploadify. Everything works except for the actual upload; the uploaded files never save to the folder. I'm guessing its the way I am using the .ashx, so any direction on whats wrong with the following code is appreciated. Thanks,
//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;
}
}
}
That's everything I have. If I try to upload a file with SWFUpload jQuery it says it succeeds but nothing ever saves to the folder. If I try with Uploadify it fails with either an HTTP Error or IO Error, and again, nothing saves. Thanks for any and all help.
Upvotes: 1
Views: 1459
Reputation: 808
I figured it out after some more time and debugging. The issue was actually with Form Authentication and occurred on any pages after the login screen. Here is the fix...
Add one of the below snippets to the web.config
If you aren't worried about any authentication try
<authorization>
<allow users="*"/>
</authorization>
If you only want to allow access to the new handler, do this
<location path="_handlers/Upload.ashx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
After I did this the debug points I had in my handler file were getting hit and I was able to solve the rest from there.
Upvotes: 2