C# Asp.Net MVC正在下载格式未知的文件
我想在我的MVC控制器中下载一个未知格式的文件 这是我的代码 公共静态void下载附件(字符串名称、字符串物理路径) {C# Asp.Net MVC正在下载格式未知的文件,c#,asp.net-mvc,C#,Asp.net Mvc,我想在我的MVC控制器中下载一个未知格式的文件 这是我的代码 公共静态void下载附件(字符串名称、字符串物理路径) { if (System.IO.File.Exists(physicalPath)) { System.IO.FileInfo file = new System.IO.FileInfo(physicalPath); byte[] fileB = File.ReadAllBytes(physicalP
if (System.IO.File.Exists(physicalPath))
{
System.IO.FileInfo file = new System.IO.FileInfo(physicalPath);
byte[] fileB = File.ReadAllBytes(physicalPath);
HttpContext context = HttpContext.Current;
context.Response.ClearHeaders();
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment; filename="+Name+";");
context.Response.ContentType = "application/force-download";
context.Response.BinaryWrite(fileB.ToArray());
context.Response.Flush();
context.Response.End();
}
}
但它不工作,但不会给出任何错误
如何解决此问题?要将文件返回到客户端,必须返回如下所示的ContentResult
public ActionResult Download()
{
return File(@"<filepath>", "application/octet-stream","<downloadFileName.ext>");
}
public ActionResult下载()
{
返回文件(@“,”应用程序/八位字节流“,”);
}
它是否适用于“应用程序/八位字节流”的ContentType?