title: Asp.net C# custom file handler
body: <p>I would like to receive files from an asp.net website but I would like to verify the request with data in a database before serving the file to the client.</p>
  
  <p>For images I would be loading using a standard html image tag like this:</p>
  
  <pre><code>'&lt;img src="/Uploads/RANDOMGUID/img.aspx" alt="The Moon" title="The Moon"&gt;
  </code></pre>
  
  <p>The requests will have a random GUID in the path which maps to a field in the database for the stored image. </p>
  
  <p>I would like to have one entry point for all the requests this could be an aspx or ashx page for example [unless there there is a better way], this would then:</p>
  
  <ul>
  <li>Parse the GUID out of the request path </li>
  <li>Verify if the requester has access to the requested image or file using database data</li>
  <li>Return an error image or file if not authorized</li>
  <li>If authorized return the file contents and set the content type</li>
  </ul>
  
  <p>How should I implement such functionality? Do I need a site wide file extension which is handled in an aspx file and returns a custom file content type?</p>