title: How to fix server error 500 web api in mobile app
body: <p>I have ASP.NET WEB API project that allows a user to upload images, then these images are viewed in another page. <br>
  The images are uploaded successfully; however, some of these images return <strong>SERVER ERROR 500</strong> when the GET method is called from a mobile app.
  <br><br>
  If I copy the url that returns the error and perform the request from the browser or postman the url works correctly so the images are found in the server.<br>
  What could be the cause that the url is not working only on mobile?
  <br>
  Here is the code that returns the image:</p>
  
  <pre><code>    [HttpGet]
      [Route("Stores/{id}/Photos/{pid}")]
      public HttpResponseMessage GetStorePhoto(int id, int pid)
      {
          using (var db = new ApplicationDbContext())
          {
              var photo = store.Photos.FirstOrDefault(p =&gt; p.Id == pid);
              if (photo == null)
                  return ImageNotFound();  //returns a default image in case image not found
  
              var filePath =
              HttpContext.Current.Server.MapPath("~/Uploads/Stores/" + photo.FileName);
  
              if (!File.Exists(filePath))
                  return ImageNotFound();
              var response = new HttpResponseMessage();
              response.Content = new StreamContent(new FileStream(filePath, FileMode.Open));
              response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
  
              return response;
          }
      }
  </code></pre>