2

我正在使用 Ext.Net 库和 ASP.net 路由。

以下页面

~/Admin/Dashboard.aspx

被路由为

administrator/fr/dashboard/

或者

administrator/en/dashboard/

我正在使用 Ext.Net FileUpload 控件。

以下代码(关于直接事件)

HttpContext.Current.Request.Files[0].SaveAs(fileName);

产生以下异常

System.Web.HttpException (0x80004005):文件“/administrator/en/dashboarddefault.aspx”不存在。在 Ext.Net.HandlerMethods.GetHandlerMethods(HttpContext context, String requestPath) 在 Ext.Net.HandlerMethods.GetHandlerMethods(HttpContext context, String requestPath) 在 Ext.Net.DirectRequestModule.ProcessRequest(HttpApplication app, HttpRequest request)

状态码:200,状态文本:OK。

如果我从

~/Admin/Dashboard.aspx

没有问题。

请帮忙。

4

1 回答 1

0

尝试使用通用处理程序。

上传.ashx:

<%@ WebHandler Language="C#" Class="upload" %>

using System;
using System.Web;
using System.IO;
using System.Web.Script.Serialization;

public class upload : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        try
        {
            HttpPostedFile postedFile = context.Request.Files[0];
            byte[] b = new byte[postedFile.ContentLength];
            postedFile.InputStream.Read(b, 0, postedFile.ContentLength);
            File.WriteAllBytes(Path.GetTempPath() + postedFile.FileName, b);
            context.Response.Write((new JavaScriptSerializer()).Serialize(new { success = true }));
        }
        catch (Exception ex)
        {
            context.Response.Write((new JavaScriptSerializer()).Serialize(new { success = false, error = ex.Message }));
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

js代码(可以适配Ext.Net或者使用CustomConfig),把这段代码组成items数组:

{
    xtype: 'fileuploadfield',
    listeners: {
        change: function () {
            var fp = this.findParentByType('panel');
            if (fp.getForm().isValid()) {
                fp.getForm().submit({
                    url: 'Handlers/upload.ashx',
                    success: function (me, o) {
                        if (o.result.success) {
                            // some code
                        } else {
                            Ext.Msg.alert('Error', o.result.error);
                        }
                    }
                });
            }
        }
    }
}
于 2012-11-18T13:01:03.380 回答