title: Return image from Controller
body: <p>Controller:</p>
  
  <pre><code>public ActionResult Beacon(string value)
  {
      var dir = Server.MapPath("/Content/Images/Sprites/");
      var path = Path.Combine(dir, "logo.png");
      return base.File(path, "image/png");
  
  }
  </code></pre>
  
  <p>Generated HTML:</p>
  
  <pre><code>&lt;img style="-webkit-user-select: none" src="http://localhost:38315/Beacon/999"&gt;
  </code></pre>
  
  <p>However the image is not displayed. In Chrome it's a small box with grey borders and in MS Edge there is a box with an "X" in it which I assume is the "File not found" image.</p>
  
  <p>I have tried returning different images (to make sure the first one was not corrupt), several Content Types but without any luck.</p>
  
  <p>I'm sure that the different files that I have tried with exists.</p>
  
  <p>I read this post: <a href="https://stackoverflow.com/questions/12803659/asp-net-mvc-img-src-server-path">ASP.Net MVC - Img Src Server Path</a></p>
  
  <p>I have tried this: </p>
  
  <pre><code>return File("~/images/beacon.png", "image/png");
  </code></pre>
  
  <p>I have tried returning a Base64 string but with no luck.</p>
  
  <p>When I run this code it states that the file do exist:</p>
  
  <pre><code>var dir = Server.MapPath("/images");
  var path = Path.Combine(dir, "beacon.png");
  var res = System.IO.File.Exists(path);
  return base.File(path, "image/png");
  </code></pre>
  
  <p>How can I return a simple image through a Controller?</p>
  
  <p><strong>* Willy David Jr Suggestion *</strong></p>
  
  <pre><code>public ActionResult Beacon(string value) {
  
  var path =  Server.MapPath(Url.Content("~/Content/Images/Sprites/")) + "logo.png";
  var theFile = new FileInfo(path);
  
  if (theFile.Exists) {
      return File(System.IO.File.ReadAllBytes(path), "image/png");
      //or return base.File(path, "image/png");
  }
      return this.HttpNotFound();                
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/JrJJW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JrJJW.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ZyVbK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZyVbK.png" alt="enter image description here"></a></p>