I have written a custom dashboard that displays members of a certain group in a table.
The dashboard is located in a custom section "Employees".
When I go to the Employees dashboard, I see a member.
If I now switch to the "Members" section, assign a member to the group there and then switch back to my Employees Dashboard, the new member is not displayed.
It only appears when I actually reload the page.
Can I somehow ensure that the back office always retrieves the latest data when I switch between sections? Or alternatively only certain sections/dashboards?
I have added the attribute "DisableBrowserCache" to my controller, but that doesn't seem to have any effect.
Update:
If I deactivate the cache via the Edge DevTools, the list is not updated either. It just looks like the "same instance" of the dashboard is always loaded for the user when they switch between the dashboards. But as soon as he reloads, a "new instance" is created, if that makes sense. That's why I assumed that deactivating the cache would solve the problem.
I also have an "EmployeesDashboardService", which I register as "Transient" in the startup. But even this is only called as soon as I refresh the page.
Here is my controller:
[
Authorize(Policy = AuthorizationPolicies.BackOfficeAccess),
Authorize(Policy = "IsCompanyAdministrator"),
DisableBrowserCache
]
public class EmployeesController(
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IEmployeesDashboardService employeesDashboardService) : Controller
{
public IActionResult Index()
{
IUser? user = backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser;
if (user == null)
{
return View();
}
IEnumerable<string> companies = user.Groups
.Where(x => !x.Alias.StartsWith("Administrators") && x.Alias.EndsWith("Administrators"))
.Select(x => x.Alias.Replace("Administrators", ""));
IEnumerable<EmployeeDto> allEmployees = new List<EmployeeDto>();
foreach (string company in companies)
{
List<EmployeeDto> tempEmployees = employeesDashboardService.GetAllEmployees(company);
allEmployees = allEmployees.UnionBy(tempEmployees, x => x.Id);
}
return View(allEmployees.ToList());
}
}
And my service:
public class EmployeesDashboardService(IMemberService memberService) : IEmployeesDashboardService
{
public List<EmployeeDto> GetAllEmployees(string companyName)
{
if (string.IsNullOrWhiteSpace(companyName))
{
return new List<EmployeeDto>();
}
IEnumerable<IMember> membersOfGroup = memberService.GetMembersByGroup(companyName);
var employees = new List<EmployeeDto>();
foreach (IMember member in membersOfGroup)
{
employees.Add(new EmployeeDto
{
Id = member.Id,
Name = member.Name
});
}
return employees;
}
}
Force reload back office when a section is opened
I have written a custom dashboard that displays members of a certain group in a table.
The dashboard is located in a custom section "Employees". When I go to the Employees dashboard, I see a member. If I now switch to the "Members" section, assign a member to the group there and then switch back to my Employees Dashboard, the new member is not displayed.
It only appears when I actually reload the page.
Can I somehow ensure that the back office always retrieves the latest data when I switch between sections? Or alternatively only certain sections/dashboards?
I have added the attribute "DisableBrowserCache" to my controller, but that doesn't seem to have any effect.
Update:
If I deactivate the cache via the Edge DevTools, the list is not updated either. It just looks like the "same instance" of the dashboard is always loaded for the user when they switch between the dashboards. But as soon as he reloads, a "new instance" is created, if that makes sense. That's why I assumed that deactivating the cache would solve the problem.
I also have an "EmployeesDashboardService", which I register as "Transient" in the startup. But even this is only called as soon as I refresh the page.
Here is my controller:
And my service:
is working on a reply...