TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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 ....
public
async Task<IActionResult> Download(
string
filename)
{
if
(filename ==
null
)
return
Content(
"filename not present"
);
var path = Path.Combine( Directory.GetCurrentDirectory(),
"wwwroot"
+ @
"\UploadFiles"
, filename);
var memory =
new
MemoryStream();
using
(var stream =
new
FileStream(path, FileMode.Open))
{
await stream.CopyToAsync(memory); }
memory.Position = 0;
return
File(memory, GetContentType(path), Path.GetFileName(path));
}
private
string
GetContentType(
string
path)
{
var types = GetMimeTypes();
var ext = Path.GetExtension(path).ToLowerInvariant();
return
types[ext];
}
private
Dictionary<
string
,
string
> GetMimeTypes()
{
return
new
Dictionary<
string
,
string
>
{
{
".txt"
,
"text/plain"
},
{
".pdf"
,
"application/pdf"
},
{
".doc"
,
"application/vnd.ms-word"
},
{
".docx"
,
"application/vnd.ms-word"
},
{
".xls"
,
"application/vnd.ms-excel"
},
{
".xlsx"
,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
},
{
".png"
,
"image/png"
}, {
".jpg"
,
"image/jpeg"
},
{
".jpeg"
,
"image/jpeg"
},
{
".gif"
,
"image/gif"
},
{
".csv"
,
"text/csv"
} };
}
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
Reply
Answers (
0
)
c# Learning Queries
Convert byte[] to IEnumerable byte[] in c#