title: Can not do Response.Redirect when I use WebClient with Silverlight 4.0 to call aspx page
body: <p>I am working on a Silverlight Project. 
  When i saved a jpg picture into a memorystream to save it
  into the Context.InputStream, it is working fine.
  I am calling an aspx page who thread the upload into the server.</p>
  
  <p>But i can not do a "response.redirect" or "server.transfer" when the upload is done or failed .
  Is it because I call  my aspx page from Silverlight using WebClient ?  </p>
  
  <p>Please find the code in Silverlight below :</p>
  
  <pre><code> private void UploadFile(string fileName, Stream data){ 
  
   UriBuilder ub = new UriBuilder("http://localhost:52544/WebForm1.aspx");
  
  //add a parameter filename  into the queryString
  
  ub.Query = string.Format("filename={0}", fileName);
  
  WebClient c = new WebClient();
  
  c.OpenWriteCompleted += (sender, e) =&gt;
     {
  
        PushData(data, e.Result);
        e.Result.Close();
        data.Close();
     };
  c.OpenWriteAsync(ub.Uri);
  }
  </code></pre>
  
  <p>On the aspx page, I have this code </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              try
              {             
                  // get the filename
  
                  string filename = Request.QueryString["filename"].ToString();
  
                  // create a file on the server dir
  
                  using (FileStream fs = File.Create(Server.MapPath("~/AppData/" + filename)))
                  {
                      SaveFile(Request.InputStream, fs);
                  }
  
                      Response.Redirect("uploadOk.aspx", true);
                  }
                  catch (Exception ex)
                  {
  
                  }
  
  
          }
  
  
          private bool SaveFile(Stream stream, FileStream fs)
          {
              bool isSaved = true;
              byte[] buffer = new byte[4096];
              int bytesRead;
              try
              {
                  // copy the stream into the file
  
                  while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
                  {
                      fs.Write(buffer, 0, bytesRead);
                  }
                  isSaved = true;
              }
              catch (Exception e)
              {
                  isSaved = false;
              }
              return isSaved;
          }
      }
  </code></pre>
  
  <p>I have tried response.redirection("uploadOk.aspx",false) too and it is not working.
  I got the following exception “[System.Threading.ThreadAbortException] = {Unable to evaluate 
  expression because the code is optimized or a native frame is on top of the call stack.}”</p>
  
  <p>Do you have an idea how i can do a redirection using a WebClient ? </p>
  
  <p>Thank you in advance</p>