I have following global filter code:
public class UserAuthorizationFilter : FilterAttribute, IAuthorizationFilter
{
private readonly IAdministratorService _administratorService;
public UserAuthorizationFilter()
{
_administratorService = IoCFactory.Container.GetInstance<IAdministratorService>();
}
public void OnAuthorization(AuthorizationContext filterContext)
{
string username = HttpContext.Current.User.Identity.Name;
IRequestMessage<string> request = MessageFactory.BuildRequestFor(username, username);
Administrator administrator = _administratorService.GetDetailByName(request).Data;
filterContext.Controller.ViewBag.Username = username;
filterContext.Controller.ViewBag.IsAdmin = administrator != null;
if (administrator != null)
{
bool isManageRole = administrator.Roles.Any(r => r.IsManageRole);
bool isManageAdministrator = administrator.Roles.Any(r => r.IsManageAdministrator);
bool isManageReviewer = administrator.Roles.Any(r => r.IsManageReviewer);
filterContext.Controller.ViewBag.IsManageRole = isManageRole;
filterContext.Controller.ViewBag.IsManageAdministrator = isManageAdministrator;
filterContext.Controller.ViewBag.IsManageReviewer = isManageReviewer;
}
}
}
and i add this filter in the Application_Start event of global.asax:
GlobalFilters.Filters.Add(new UserAuthorizationFilter(), 0);
When I updating Administrator role property e.g IsManageRole from true
to false
, data was updated to database successfully. Yet in UserAuthorizationFilter
property role in administrator object doesn't updated, its still load true
value . I have tried calling sessionFactory.Evict(typeof(Role))
, session.Clear()
but find no luck. Still the data won't load new updated Role property. property was updated if I restart the web application.
How do I solve this? Why nhibernate cache won't be clear and updated with functions above, any suggestion? Please help..