2011-12-03 7 views
2

私はASP.netルーティングと一緒にExt.Netライブラリを使用しています。Ext.Net FileuploadとASP.netルーティング

次のページ

~/Admin/Dashboard.aspx 

は私がExt.NetのFileUploadコントロールを使用しています

administrator/fr/dashboard/ 

または

administrator/en/dashboard/ 

としてルーティングされます。ファイル 「/管理者/ EN/dashboarddefault:

(直接イベントに)次のコード

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

は、次の例外

System.Web.HttpException(0x80004005が)を生成します。 aspx 'は存在しません。 Ext.Net.DirectRequestModule.ProcessRequest(のHttpApplicationアプリ HttpRequestの要求)で Ext.Net.HandlerMethods.GetHandlerMethods Ext.Net.HandlerMethods.GetHandlerMethodsで(のHttpContextコンテキスト、文字列 requestPath)(のHttpContext コンテキスト、文字列requestPath)で

ステータスコード:200、ステータステキスト:OK。

私は

~/Admin/Dashboard.aspx 

から同じことを行う場合は問題ありません。

助けてください。

+1

を提供することができますコードとルーティングルールの – Baidaly

答えて

0

汎用ハンドラを使用してください。

upload.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を使用することができます)、項目のアレイを形成するために、このコードを置く:あなたは、いくつかの例を

{ 
    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); 
         } 
        } 
       }); 
      } 
     } 
    } 
}