I have a custom AuthorizeAttribute which checks if a user can access a particular action:
public class UserCanAccessArea : AuthorizeAttribute
{
readonly IPermissionService permissionService;
public UserCanAccessArea() :
this(DependencyResolver.Current.GetService<IPermissionService>()) { }
public UserCanAccessArea(IPermissionService permissionService)
{
this.permissionService = permissionService;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
string AreaID = httpContext.Request.RequestContext.RouteData.Values["AreaID"] as string;
bool isAuthorized = false;
if (base.AuthorizeCore(httpContext))
isAuthorized = permissionService.UserCanAccessArea(AreaID, httpContext.User);
return isAuthorized;
}
}
The code simply checks that the User is authenticated, then checks the Users corresponding entry in an application specific database to determine if the User has access to the specified Area. Currently, this is simply a "CanAccessAreas" flag on the table.
The problem I am having is that when an Admin updates the "CanAccessAreas" flag for a User, the User still cannot access the area. Noted behaviour:
- Logging out/in does not solve this for the User.
- Running the code locally does not reproduce this behaviour.
- Republishing the code solves the problem for the User until the flag is updated.
- Each user is presented with a menu, which shows what they can access. This updates instantly when an Admin updates a Users flag.
It seems like the AuthorizeAttribute is caching the result but I'm unsure how to prevent this securely if this is the case.