简体   繁体   English

Chrome浏览器中File方法的奇怪行为

[英]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 ?) 在本地IIS Express上调试/运行时,它可以正常工作-文件名正确且下载正确,但是在我的生产服务器(iis8.5)上,文件名带有名称(为什么?)

"unknown.pdf____________________________________________________________________________________________________________________________________________________________________________________________". “ unknown.pdf ____________________________________________________________________________________________________________________________________________________________________________________________________________________________”。

It seems that it is Google-Chrome behawior, on Edge, Firefox it looks better. 看来这是Google-Chrome的行为,在Edge,Firefox上看起来更好。 Chrome is unfortunately in common use in company so it makes problem. 不幸的是,Chrome在公司中经常使用,因此会引起问题。 Haven't found any solution so far. 到目前为止尚未找到任何解决方案。

Edit: IIS mime types are set in IIS by default : ex: application/pdf 编辑:IIS MIME类型默认在IIS中设置:例如:application / pdf

Solved anyway with myself - this happens when application is .net 4.5.2 but server has .net 4.5 only installed. 无论如何与我自己解决-当应用程序是.net 4.5.2但服务器仅安装.net 4.5时,会发生这种情况。 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. 感谢所有在此主题上花费了一些时间的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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