public async Task <IActionResult> OnGet() { if (!User.Identity.IsAuthenticated) { return(RedirectToPage("/Account/Login", new { area = "Identity" })); } try { int?UserGroupID = HttpContext.Session.GetInt32("UserGroupID"); var user = await _userManager.GetUserAsync(User); PotAccess = await _siteData.GetPotAccess(user.Id.ToString(), UserGroupID); int index = PotAccess.FindIndex(item => item.PotID == 7); if (index == -1) { return(RedirectToPage("/Account/AccessDenied", new { area = "Identity" })); } string cs = _config.GetConnectionString("Default"); HolidayDetails = _HolidayData.GetHolidayDetails(Id).Result.FirstOrDefault(); //Fetch all files in the Folder (Directory). string holidayPath = "images\\Holiday\\" + Id; var path = Path.Combine(_environment.WebRootPath, holidayPath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string[] filePaths = Directory.GetFiles(path); //Copy File names to Model collection. FileNameList = new List <FileModel>(); foreach (string filePath in filePaths) { FileNameList.Add(new FileModel { FileName = Id + "/" + Path.GetFileName(filePath) }); } if (HolidayDetails.UserGroupID != UserGroupID) { return(RedirectToPage("/Account/AccessDenied", new { area = "Identity" })); } return(Page()); } catch (Exception ex) { Log.Error(ex.ToString()); throw new Exception(ex.ToString()); } }