Download File To Browser Using .net Core Razor Pages ((exclusive)) May 2026
If the file exists on the server's disk, use PhysicalFile . This requires an absolute path.
To trigger these handlers from your .cshtml file, you can use anchor tags or form buttons with the asp-page-handler attribute. Download download file to browser using .net core razor pages
Use this when you generate data on the fly, such as a dynamically created CSV or a file retrieved from a database as a byte array. If the file exists on the server's disk, use PhysicalFile
To trigger a download instead of displaying content inline (like a PDF opening in the browser), the server must send a Content-Disposition header set to attachment along with a filename. Most built-in .NET file results handle this automatically when you provide a fileDownloadName parameter. Common Implementation Methods Download Use this when you generate data on
Use a MimeType Provider to automatically determine the correct Content-Type for different file extensions.