這裏是我的代碼,我試圖按照下載文件的功能,但它無法正常工作。它不顯示保存文件對話框。MVC 4文件下載
protected virtual FileResult Download(string FileName, string FilePath)
{
Response.AppendHeader("Content-Length", FileName.Length.ToString());
return File(FilePath, "application/exe", FileName);
}
並試圖通過這種方式也:
protected virtual ActionResult Download(string FileName, string FilePath)
{
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.AppendHeader("Content-Length", FileName.Length.ToString());
Response.ContentType = "application//x-unknown";
Response.WriteFile(FilePath.Replace("\\", "/"));
Response.Flush();
Response.End();
}
但都沒有工作。我錯過了什麼?
我希望你對安全有所瞭解問題你的文件路徑和文件名變量會與... – TGlatzer
文件名長度!=內容長度。此外,其可能的瀏覽器阻止可執行文件下載。我知道我的IE瀏覽器確實如此......而Chrome卻拋出了一個「你絕對確定嗎?」提示。 –
看到這個類似的問題:http://stackoverflow.com/questions/3604562/download-file-of-any-type-in-as-net-mvc-using-fileresult –