2017-05-11 2 views
0

ich binde DL-Link zu machen, damit andere nicht die gleiche Datei, indem sie den Austausch dl könnte Bisher habe ich diesen Code gefundenWie erstelle ich austauschbare Download-Links?

public FileResult Download() 
{ 
    byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext"); 
    string fileName = "myfile.ext"; 
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); 
} 

es wird nicht austauschbar Links machen, wie können wir tun Das?

Antwort

1

Versuchen Sie dieses Beispiel:

public ActionResult Download() 
{ 
    var [email protected]"c:\folder\myfile.ext"; 
    var fileBytes = System.IO.File.ReadAllBytes(filePath); 
    var response = new FileContentResult(fileBytes, "application/octet-stream") 
    { 
     FileDownloadName = Path.GetFileName(filePath) 
    }; 
    return response; 
}