Asp.net mvc 2 ASP.NET MVC:可以通过FileContentResult返回MSI文件而不破坏安装包吗?

Asp.net mvc 2 ASP.NET MVC:可以通过FileContentResult返回MSI文件而不破坏安装包吗?,asp.net-mvc-2,windows-installer,streamreader,filecontentresult,Asp.net Mvc 2,Windows Installer,Streamreader,Filecontentresult,我使用此代码返回FileContentResult和MSI文件,供用户在我的控制器中下载: using (StreamReader reader = new StreamReader(@"c:\WixTest.msi")) { Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd()); return File(bytes, "text/plain", "download.msi"); } 我可以下载该文件,但当我尝试

我使用此代码返回FileContentResult和MSI文件,供用户在我的控制器中下载:

using (StreamReader reader = new StreamReader(@"c:\WixTest.msi"))
{
    Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd());

    return File(bytes, "text/plain", "download.msi");
}
我可以下载该文件,但当我尝试运行安装程序时,会收到一条错误消息,上面说:

无法安装此安装包 开的。联系应用程序供应商 要验证这是一个有效的Windows 安装程序包

我知道问题不是C:\WixTest.msi,因为如果我使用本地副本,它可以正常运行。我不认为我使用了错误的MIME类型,因为我可以通过下载后正确运行的FilePathResult(不使用StreamReader)使用File.Copy并返回复制的文件来获得类似的结果

但是,我需要使用FileContentResult,这样我就可以删除正在制作的文件的副本(一旦将其加载到内存中,我就可以这样做)

我想我是在通过复制或编码文件使安装包无效。有没有一种方法可以将MSI文件读入内存,并通过FileContentResult返回它,而不会损坏安装包

解决方案:

using (FileStream stream = new FileStream(@"c:\WixTest.msi", FileMode.Open))
{
    BinaryReader reader = new BinaryReader(stream);
    Byte[] bytes = reader.ReadBytes(Convert.ToInt32(stream.Length));

    return File(bytes, "application/msi", "download.msi");
}

尝试使用二进制编码和内容类型
application/msi
,而不是
text/plain
——它不是ASCII或文本内容,因此会损坏文件