title: How to make a download file response in .net core?
body: <p>I'm using <code>endpoints.Map(&quot;/{*name}&quot;, RequestDelegate)</code> method to make a download file API.</p>
  <p>In the <code>RequestDelegate</code> handler method, I'm using <code>await context.Response.SendFileAsync(IFileInfo)</code> method to return the file.</p>
  <p>Then, I request this API in browser, but the browser did not download it, instead of showing the file content in browser directly. What's missing from my code. I want the browser to download the file.</p>
  <p><a href="https://i.stack.imgur.com/POk6Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/POk6Q.png" alt="Screenshoot" /></a></p>
  <p><code>await context.Response.SendFileAsync(GetFile(val));</code></p>
  <pre><code>private IFileInfo GetFile(string file_name)
  {
      string downloadPath = Configuration.GetSection(&quot;DownloadFilePath&quot;).Get&lt;string&gt;();
      IFileProvider provider = new PhysicalFileProvider(AppDomain.CurrentDomain.BaseDirectory);
      IFileInfo fileInfo = provider.GetFileInfo($&quot;{downloadPath}/{file_name}&quot;);
      return fileInfo;
  }
  </code></pre>