title: Display Azure blob encrypted picture on ImageControl
body: <p>This is my first question on Stackoverflow.</p>
  
  <p>I'm facing an architecture issue more than a programming one.</p>
  
  <p>I'll explain the topic : 
  I'm working with Microsoft Azure Cloud Service solution.</p>
  
  <p>I have a WorkerRole which encrypts uploaded pictures and stores them in a Blob.</p>
  
  <p>Then I have a WebRole with which I want to display this picture in a browser, within an image controller.</p>
  
  <p>I managed to get an encrypted picture from a blob to local storage and to decrypt it.</p>
  
  <p>At this point, I looked how to display pictures stored in WebRole LocalStorage when I found <a href="https://stackoverflow.com/questions/17874648/web-role-local-storage-uri">this</a>. The answer explains that it's a bad idea to use local storage to serve picture since each request can hit different instances of my webRole.</p>
  
  <p>So, here i'm stuck, how can I serve my decrypted pictures to my image controller without having an unencrypted copy of my picture in the blob ?</p>
  
  <p><strong>Solution</strong>
  Define a web handler which download picture from blob to webrole, then decrypt it and return this.</p>
  
  <pre><code>public class Images : IHttpHandler
  {
      public void ProcessRequest(HttpContext context)
          {
              String imgPath;
              String imgName = context.Request.QueryString["imgName"];
              imgPath = getFromStorage(imgName);
              context.Response.ContentType = "image/png";
              context.Response.WriteFile(imgPath);
          }
  }
  </code></pre>
  
  <p>In your image web control : </p>
  
  <pre><code>&lt;asp:Image ID="imgViewer" ImageUrl="Images.ashx?imgName=mypicture.png"/&gt;
  </code></pre>