0

Been stuck at this part for a few days that i still could not pass any query string to generic handler.

my code is as follows:

1st: query string is passed into Upload.aspx. and i retrieve it in the page load section:

My Upload.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {

        int userId = Convert.ToInt32(Request.QueryString["userid"]);
        int upload = Convert.ToInt32(Request.QueryString["upload"]);
        int childId = Convert.ToInt32(Request.QueryString["childid"]);
    }

My Upload.aspx

<script type="text/javascript">
   // <![CDATA[
   $(document).ready(function() {
   $('#fileInput').uploadify({
   'uploader': 'uploadify/uploadify.swf',
   'script': 'Upload.ashx',
   'cancelImg': 'uploadify/cancel.png',
   'auto': true,
   'multi': true,
   'fileDesc': 'Image Files',
   'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
   'queueSizeLimit': 90,
   'sizeLimit': 4000000,
   'buttonText': 'Choose Images',
   'folder': '/uploads',
   'onAllComplete': function(event, queueID, fileObj, response, data) {

   }
 });

});

My upload.ashx

public void ProcessRequest(HttpContext context)
    {

        try
        {
            HttpPostedFile file = context.Request.Files["Filedata"];
            Global.myDBManager.ConnectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
            Global.myDBManager.DataProviderType = DBMgr.DataProvider.MySql;
            Global.myDBManager.Connect();
            int id = 1 + Convert.ToInt32(Global.myDBManager.ExecuteScalar("Select id from picture order by picture_id desc limit 1"));
            Global.myDBManager.ExecuteScalar("Insert into image(picture_id,user_id) VALUE('" + id + "', '" + userId + "')");
            file.SaveAs("C:\\" + id.ToString() + file.FileName);
            context.Response.Write("1");
        }
        catch (Exception ex)
        {
            context.Response.Write("0");
        }
}

how do i pass the query into upload.ashx? where userId is the query that im trying to pass.

thanks in advance !

4

1 に答える 1

1

これをProcessRequestメソッドで使用します。Context.Requestクエリ文字列パラメーターを取得するために使用できます。

int userId = Convert.ToInt32(Context.Request.QueryString["userid"]);

アプリケーションで URL マッピングを行っていることを確認してくださいweb.config

例えば

<system.web>
    <urlMappings enabled="true">
    <add url="~/Upload.aspx" mappedUrl="~/Upload.ashx"/>
    </urlMappings>
    ...

このリンクは、汎用ハンドラーの作成に関するアイデアを提供する場合があります。

于 2011-08-15T04:07:23.497 に答える