U Thu

U Thu

  • NA
  • 336
  • 22.3k

ASP.NET Core file download from IIS Server Problem

Feb 6 2018 3:31 AM
My Problems is File download from IIS Server of UploadFiles Folder.I am using VS2017 in running File Upload and Download is OK.But Published to IIS Server in download is problem.Please help me.My Download Method is ....
  1. public async Task<IActionResult> Download(string filename)  
  2. {  
  3. if (filename == null)  
  4. return Content("filename not present");  
  5. var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot" + @"\UploadFiles", filename);  
  6. var memory = new MemoryStream();  
  7. using (var stream = new FileStream(path, FileMode.Open))  
  8. {  
  9. await stream.CopyToAsync(memory); }  
  10. memory.Position = 0;  
  11. return File(memory, GetContentType(path), Path.GetFileName(path));  
  12. }  
  13. private string GetContentType(string path)  
  14. {  
  15. var types = GetMimeTypes();  
  16. var ext = Path.GetExtension(path).ToLowerInvariant(); return types[ext];  
  17. }  
  18. private Dictionary<stringstring> GetMimeTypes()  
  19. {  
  20. return new Dictionary<stringstring>  
  21. {  
  22. {".txt""text/plain"},  
  23. {".pdf""application/pdf"},  
  24. {".doc""application/vnd.ms-word"},  
  25. {".docx""application/vnd.ms-word"},  
  26. {".xls""application/vnd.ms-excel"},  
  27. {".xlsx""application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},  
  28. {".png""image/png"}, {".jpg""image/jpeg"},  
  29. {".jpeg""image/jpeg"},  
  30. {".gif""image/gif"},  
  31. {".csv""text/csv"} };  
  32. }  
And My Index Of Download Link is
 
<a asp-action="Download" asp-route-filename="@item.UploadFilePath"> Download a>
 
Localhost in upload and download is ok. But IIS Published in download is this error
 
Route URL IS REHPApplication/HQAdmin/Download?filename=DownloadFile.pdf
Error.
An error occurred while processing your request.
DEVELOPMENT MODE
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
 
Please help me teachers