简体   繁体   中英

Strange behavior of File method on Chrome Browser

In (one) of my application's controller is defined action/method that allows download file.

public FileResult PDFDownloadA(int attachementid)
{
    string filepath = "";
    byte[] pdfByte;

    SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.
                                            ConnectionStrings["Zalaczniki"].ConnectionString);
    conn.Open();
    using (var sqlquery = new SqlCommand("SELECT DDOKUMENT,DFILENAME from ATTACHEMENTS WHERE ID = @id", conn))
    {
        sqlquery.Parameters.AddWithValue("id", attachementid);
        using (var wynik = sqlquery.ExecuteReader())
        {
            wynik.Read();
            var blob = new Byte[wynik.GetBytes(0, 0, null, 0, int.MaxValue)];
            wynik.GetBytes(0, 0, blob, 0, blob.Length);
            filepath = wynik.GetString(1);
            pdfByte = blob;
        }
    }

    conn.Close();

    return File(pdfByte, "application/pdf", (filepath == "") ? "temp.pdf" : filepath);
}

And problem part:

It works fine when debugging/runnning on local IIS Express - file got its proper name and downloads properly, but on my production server (iis8.5) file dowloads with name (why ?)

"unknown.pdf____________________________________________________________________________________________________________________________________________________________________________________________".

It seems that it is Google-Chrome behawior, on Edge, Firefox it looks better. Chrome is unfortunately in common use in company so it makes problem. Haven't found any solution so far.

Edit: IIS mime types are set in IIS by default : ex: application/pdf

Solved anyway with myself - this happens when application is .net 4.5.2 but server has .net 4.5 only installed. Another functionalities (forms/queries etc) worked before perfect .

Now it works perfect. Maybe it will be usefull for someone. Thanks for everyone that spent some time on this subject.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM