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 !

foo ming xiang
  • 65
  • 1
  • 10

1 Answers1

1

Use this in ProcessRequest method. You can use Context.Request to get the querystring parameters.

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

Make sure you have done url mapping in your application web.config.

E.g.

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

This link might give you some idea on writing generic handlers.

ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124