2011-12-07 9 views
1

私はこれを数日間は見てきましたが、成功しませんでした。私はウェブサイト用のマルチファイルアップロードシステムを作成しようとしています。私はSWFUploadとUploadifyを含むいくつかのjQueryプラグインを試しました。実際のアップロード以外はすべて動作します。アップロードされたファイルはフォルダに保存されません。私はその方法を私が.ashxを使用していると推測しているので、次のコードで何が間違っているのいずれかの方向に感謝します。ありがとう、.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; 
    } 
} 
} 

これはすべてです。 SWFUpload jQueryを使ってファイルをアップロードしようとすると、成功すると言いますが、これまでにフォルダに保存したことはありません。 Uploadifyを試すと、HTTPエラーまたはIOエラーで失敗し、何も保存されません。すべての助けをありがとう。

+0

ashxファイルはメンバーエリアなどにありますか?それはセッションの問題かもしれません。 –

答えて

2

もう少し時間をかけてデバッグしてみました。この問題は実際にはフォーム認証で発生し、ログイン画面の後のすべてのページで発生しました。あなたが任意の認証を心配していない場合はここで修正がある...

はあなただけしたい場合は

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

を試してweb.config

に以下のスニペットの1を追加します。新しいハンドラにアクセスできるようにする

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

これを実行した後、私がハンドラファイルに持っていたデバッグポイントがヒットしていました。そこから残りを解決することができます。

関連する問題