Avoid donut caching when a user logs in as administrator in form authentication mode?

I would like to avoid caching if the user is logged in with forms authentication in the admin group.

I redefined the cache attribute and applied it at the controller level. However, the NonAdmin method is not called through validationcallback!

public class OutputCache_NonAdmin : DonutOutputCacheAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext.Current.Response.Cache.AddValidationCallback(NonAdmin, null);
        base.OnActionExecuting(filterContext);
    }

    private void NonAdmin(HttpContext httpContext, object data, ref HttpValidationStatus httpValidationStatus)
    {
        //-- METHOD DOES NOT GET CALLED!
        httpValidationStatus = FormsAuthenticationService.IsLoggedIn("Admin") 
            ? HttpValidationStatus.IgnoreThisRequest 
            : HttpValidationStatus.Valid;
    }
}

How can I achieve no caching when a user logs in?

+4
source share

All Articles