【发布时间】:2021-12-07 07:11:08
【问题描述】:
我正在设计一个教育网站。当用户下载培训课程时,我希望这个下载(培训课程)以压缩(拉链)的形式完成,请给出解决方案
我的代码:
public Tuple<byte[],string,string> DownloadFile(long episodeId)
{
var episode=_context.CourseEpisodes.Find(episodeId);
string filepath = Path.Combine(Directory.GetCurrentDirectory(),
"wwwroot/courseFiles",
episode.FileName);
string fileName = episode.FileName;
if(episode.IsFree)
{
byte[] file = System.IO.File.ReadAllBytes(filepath);
return Tuple.Create(file, "application/force-download",fileName);
}
if(_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
{
if(IsuserIncorse(_httpContextAccessor.HttpContext.User.Identity.Name,
episode.CourseId))
{
byte[] file = System.IO.File.ReadAllBytes(filepath);
return Tuple.Create(file, "application/force-download", fileName);
}
}
return null;
}
【问题讨论】:
-
您不能同时使用 ASP.NET Core 和古老的 ASP.NET MVC 4。您实际使用的是什么?
-
不,我只使用 ASP.NET Core 和模板 RazorPage
标签: asp.net-core asp.net-core-razor-pages