title: passing information from ASP.NET ashx to aspx
body: <p>I am using Jquery ajax to Upload files to my database to produce a progress bar..</p>
  
  <p>The problem is, I have no way of passing the uploaded filename to my backend code. I can easily enough pass the filename that was sent via the user using Hiddenfields and jquery, however my ASHX Handler may have renamed it if that file exists. I tried to create a Session["variable"] in the ASHX file with the passed context, however it was null..</p>
  
  <p>Here is my Javascript :</p>
  
  <pre><code>$(function () {
      $("#&lt;%=supplierInfo.FUclientID %&gt;").makeAsyncUploader({
          upload_url: '&lt;%=ResolveUrl("~/Controls/UploadHandler.ashx")%&gt;', // Important! This isn't a directory, it's a HANDLER such as an ASP.NET MVC action method, or a PHP file, or a Classic ASP file, or an ASP.NET .ASHX handler. The handler should save the file to disk (or database).
          flash_url: '../../Scripts/swfupload.swf',
          button_image_url: '../../Scripts/blankButton.png',
          disableDuringUpload: 'INPUT[type="submit"]',
          upload_success_handler: function () {
              var hiddenfield = document.getElementById('&lt;% =hdnTest.ClientID %&gt;');
              hiddenfield.value = "test";
  
              $("span[id$=_completedMessage]", container).html("Uploaded &lt;b&gt;{0}&lt;/b&gt; ({1} KB)"
                          .replace("{0}", file.name)
                          .replace("{1}", Math.round(file.size / 1024))
                      );
          }
      });
  });
  </code></pre>
  
  <p>The ASHX Handler:</p>
  
  <pre><code>&lt;%@ WebHandler Language="C#" Class="UploadHandler" %&gt;
  
  using System;
  using System.Web;
  using System.IO;
  
  public class UploadHandler : IHttpHandler {
  
      public void ProcessRequest (HttpContext context) {
  
          string strFileName = Path.GetFileName(context.Request.Files[0].FileName);
          string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();
  
          int i = 0;
          while (File.Exists(context.Server.MapPath("~/images/Upload/SupplierImg") + "/" + strFileName))
          {
              strFileName = Path.GetFileNameWithoutExtension(strFileName) + i.ToString() + strExtension;
          }
  
          string strLocation = context.Server.MapPath("~/images/Upload/SupplierImg") + "/" + strFileName;
          context.Request.Files[0].SaveAs(strLocation);
  
          context.Response.ContentType = "text/plain";
          context.Response.Write("OK");
  
      }
  
      public bool IsReusable {
          get {
              return false;
          }
      }
  
  }
  </code></pre>