title: A Path Traversal vulnerability in asp.net core
body: <p>I already tried these solutions</p>
  <p><a href="https://stackoverflow.com/questions/17045117/does-my-code-prevent-directory-traversal-in-c">Does my code prevent directory traversal in C#?</a></p>
  <p><a href="https://stackoverflow.com/questions/37383143/is-path-traversal-vulnerabilities-possible-in-my-below-code">Is Path Traversal Vulnerabilities possible in my below code?</a></p>
  <p><a href="https://blog.mindedsecurity.com/2018/10/how-to-prevent-path-traversal-in-net.html" rel="nofollow noreferrer">How to prevent Path Traversal in .NET</a></p>
  <p><a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/1e573dd1-8b52-4c25-89c8-1e53a08ffe2f/how-to-avoid-directory-traversal-in-my-code?forum=csharpgeneral" rel="nofollow noreferrer">How to avoid Directory Traversal in my code</a></p>
  <p>But still, Checkmarx scanning giving a security issue, below is the code</p>
  <pre><code>public FileContentResult GetImageFromFilePath(string filePath)
          {
              byte[] image = null;
              if (!string.IsNullOrEmpty(filePath))
              {
                  image = System.IO.File.ReadAllBytes(filePath);
              }
              if (image == null)
                  return null;
              return File(image, &quot;image/jpeg&quot;);
          }
  </code></pre>
  <p>The issue is on this line of code <code>image = System.IO.File.ReadAllBytes(filePath);</code></p>
  <p>Please let me known how to solve this security issue.</p>
  <p>Thanks in advance.</p>