title: ASP.NET MVC controller handling file downloads
body: <p>I've built a controller in MVC 5 to handle file downloads protected by login. The controller works fine without the pdf extension, ie paths like /media/1001/secretpdffile will download a file at App_Data/media/1001/secretpdffile.pdf only if the user is logged in. </p>
  
  <p>I would like to have the pdf extension on the paths but as soon as I add it (of course also dropping the pdf I'm adding in the controller) that I get a 404 error. </p>
  
  <p>This is my route</p>
  
  <pre><code>routes.MapRoute(
      name: "Media",
      url: "media/{mediaid}/{filename}",
      defaults: new { controller = "Media", action = "Get" }
  );
  </code></pre>
  
  <p>I've seen a lot of places that try to solve this with &lt;httpRuntime relaxedUrlToFileSystemMapping="true" /&gt; or with setting a path with System.Web.Handlers.TransferRequestHandler in web.config but I haven't had any luck with that.</p>