File download is working fine in Microsoft Edge, Firefox and Safari browsers but in Chrome instead of downloading a file, it's opening the file directly. I would also want to add that this behaviour is only when the application is hosted in IIS and in IISExpress all browsers work fine. Why am I getting this behaviour in IIS with Chrome and how to resolve the issue?
protected void btnDownloadFile_Click(object sender, EventArgs e)
{
string fileFullPath = @"E:\AllFiles\History\John's certificate.doc";
FileInfo fileInfo = new FileInfo(fileFullPath);
if (fileInfo.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileInfo.Name + "\"");
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = MIMETypeHelper.GetMimeType(fileInfo.Extension); // This method supplies the contenttype based on file extention for example if .doc extension returns application/msword
Response.Flush();
Response.TransmitFile(fileInfo.FullName);
Response.End();
}
}
I noticed that this is Chrome's feature and to turn it off I did the following steps: