0
로그인 할 때 권한이 부여 된 사용자에게 내 MVC5 응용 프로그램에서 파일 다운로드를 제공하는 것을보고 있습니다. 나는 사람이 허가됩니다 때MVC5 권한 부여 파일 다운로드 MVC5
이App_Data/Files/{ItemName}/{FileName}.{FileExtension}
자산 (FileExtension 대부분의 경우에 우편 번호입니다) 아래로
{**AssetId**, ItemName, FileName, FileExtension, FileLive}
ApprovedToDownload
{**Id**, **userId**, **AssetId**, GUID, ExpireDate, StartDate}
를 물리적 경로 구조를 사용하고자하는 userId는 위와 같이 ApprovedToDownload 테이블과 파일에 액세스하기 위해 만든 동적 GUID에 연결됩니다.
/my-assets/download/GUID
컨트롤러
[Authorize]
[Route("my-assets/download/{id}",Name="mydload")]
[HttpGet]
public FileContentResult Download(Guid? id)
{
int userId = User.Identity.GetUserId<int>();
if (id == null) {
throw new HttpException(404, "Not found");
}
var fzip = db.ApprovedToDownloads.SingleOrDefault(a => a.GUID == id && a.UserId == userId && a.FileLive && a.ExpireDate <= DateTime.Today);
string fid = id.Value.ToString();
string fldr=fzip.Asset.ItemName;
string fnom = fzip.Asset.FileName;
string fext = fzip.Asset.FileExtension;
// Read bytes from disk
byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Files/"+fldr+"/"+fnom+"."+fext));
return File(fileBytes, "application/zip", fid+"."+fext);
}
보안을 염두에두고이를 구현하기위한 최선 옵션은 무엇입니까 같은 URL로 파일을 다운로드 할 사람? 다른 말로하면이 문제에 직면하고 모범 사례의 방향으로 나를 지적 할 수 있다면 누구든지 조언을 해줄 수 있습니다.