2

ASP.NET webforms プロジェクトで Uploadify を使用しようとしています。問題は、私のスクリプトが汎用ハンドラーを呼び出していないことです。これがスクリプトです。

<input id="fileInput" name="fileInput" type="file" />
<script type="text/javascript">
    $(document).ready(function() {
    $('#fileInput').uploadify({
        'uploader': '/Ferramenta/Comum/Uploadify/uploadify.swf',
        'script': 'UploadTest.ashx',
        'cancelImg': '/Ferramenta/Comum/Uploadify/cancel.png',
        'folder': "/Ferramenta/Geral/",
        'auto': true,
        'onError': function(event, queueID, fileObj, errorObj) {
            alert('error');
        },
        'onComplete': function(event, queueID, fileObj, response, data) {
            alert('complete');
        },
        'buttonText' : 'Buscar Arquivos'
    });
});
</script>

これは汎用ハンドラーのコードです (テスト用)。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;

namespace Tree.Ferramenta.Geral
{
    public class UploadTest : IHttpHandler
    {
        public void ProcessRequest(HttpContext context) 
        {
            context.Response.Write("1");
        }

        public bool IsReusable
        {
             get
             {
                return false;
             }
        }
    }
}

何か案は ?ありがとう !

4

5 に答える 5

1

コードを IE と Firefox で試しましたか? Firefox でのみこの問題が発生する場合は、次のコードを使用して Global.asax を作成してみてください (コードは VB.NET にあるだけです)。

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    '' Fix for the Flash Player Cookie bug in Non-IE browsers.
    '' Since Flash Player always sends the IE cookies even in FireFox
    '' we have to bypass the cookies by sending the values as part of the POST or GET
    '' and overwrite the cookies with the passed in values.

    '' The theory is that at this point (BeginRequest) the cookies have not been ready by
    '' the Session and Authentication logic and if we update the cookies here we'll get our
    '' Session and Authentication restored correctly
    Try
        Dim session_param_name As String = "ASPSESSID"
        Dim session_cookie_name As String = "ASP.NET_SESSIONID"

        If HttpContext.Current.Request.Form(session_param_name) IsNot Nothing Then
            UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form(session_param_name))
        ElseIf HttpContext.Current.Request.QueryString(session_param_name) IsNot Nothing Then
            UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString(session_param_name))
        End If
    Catch ex As Exception

    End Try

    Try
        Dim auth_param_name As String = "AUTHID"
        Dim auth_cookie_name As String = FormsAuthentication.FormsCookieName

        If HttpContext.Current.Request.Form(auth_param_name) IsNot Nothing Then
            UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form(auth_param_name))
        ElseIf HttpContext.Current.Request.QueryString(auth_param_name) IsNot Nothing Then
            UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString(auth_param_name))
        End If
    Catch ex As Exception

    End Try
End Sub

Private Sub UpdateCookie(ByVal cookie_name As String, ByVal cookie_value As String)
    Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies.Get(cookie_name)

    If cookie Is Nothing Then
        cookie = New HttpCookie(cookie_name)
    End If

    cookie.Value = cookie_value
    HttpContext.Current.Request.Cookies.Set(cookie)
End Sub

そして、次のように uploadify を呼び出します。

<input id="fileInput" name="fileInput" type="file" />
<script type="text/javascript">
    $(document).ready(function() {
    var AUTHID = '<%= IIf(Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing, String.Empty, Request.Cookies(FormsAuthentication.FormsCookieName).Value) %>';
    var ASPSESSID = '<%= Session.SessionID %>';
    $('#fileInput').uploadify({
        'uploader': '/Ferramenta/Comum/Uploadify/uploadify.swf',
        'script': 'UploadTest.ashx',
        'scriptData': { 'ASPSESSID': ASPSESSID, 'AUTHID': AUTHID },
        'cancelImg': '/Ferramenta/Comum/Uploadify/cancel.png',
        'folder': "/Ferramenta/Geral/",
        'auto': true,
        'onError': function(event, queueID, fileObj, errorObj) {
            alert('error');
        },
        'onComplete': function(event, queueID, fileObj, response, data) {
            alert('complete');
        },
        'buttonText' : 'Buscar Arquivos'
    });
});
</script>
于 2010-05-04T20:26:43.423 に答える
1

ブレークポイントを入れてProcessRequest..発火しますか?

Web サイトのコンテンツが公開されていない場合は、ハンドラーへの承認アクセスを追加してweb.config、回避する必要があります。 HTTP Error

<location path="Upload.ashx">
   <system.web>
     <authorization>
       <allow users="*"/>
     </authorization>
   </system.web>
 </location>
于 2011-10-07T14:23:33.803 に答える
1

ハンドラー クラス (UploadTest.ashx) の名前空間がマークアップとコード ビハインドで同じかどうかを確認できます。私にとっては、それが同じ問題の原因でした。

于 2010-11-05T12:52:28.267 に答える
0

.ashx ファイルを直接参照します。エラーは発生しますか?

firebug をダウンロードし、JavaScript エラーも発生するかどうかを確認します。

以下を追加することもできます。

context.Response.ContentType = "text/plain";
context.Response.StatusCode = 200;
于 2010-03-04T15:31:23.307 に答える
0

サイトは SSL に対応していますか? 私は同じ問題を抱えていましたが、無効な証明書を持っていたことが原因であることが判明しました。不正な証明書を含むファイルをアップロードしている場合、Flash がエラーを埋めていることに関係があります。

于 2012-02-28T01:51:42.380 に答える