直播網站,我有這樣的功能:無法下載文件到MVC 5
public ActionResult Download(string FileName)
{
if (FileName != null)
{
string filepath = AppDomain.CurrentDomain.BaseDirectory + "/uploads/" + FileName;
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
string contentType = MimeMapping.GetMimeMapping(filepath);
var cd = new System.Net.Mime.ContentDisposition
{
FileName = FileName,
Inline = true,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(filedata, contentType);
}
return RedirectToAction("Index");
}
相同的代碼在本地服務器工作,但不是在活的服務器,任何人都可以告訴我原因嗎?
首先我會看是'filepath' – jamiedanq
你可以用這種方式來嘗試:刪除「string filepath = ...」行並更新「byte [] filedata = ...」行:byte [] filedata = System.IO.File.ReadAllBytes(Server.MapPath (「〜/ uploads /」+ FileName +「」)); – kkakkurt
請閱讀[問]並解釋這是如何「無法正常工作」。 – CodeCaster