I have the following action method with a cache on server setting:
[CheckUserPermissions(Action = "", Model = "Admin")]
[OutputCache(CacheProfile = "short", Location = OutputCacheLocation.Server, VaryByHeader = "X-Requested-With")]
public ActionResult SystemInfo(int page = 1,bool forTechAudit=false)
{
And the CheckUserPermision
action filter will return unauthorized message to the users who do not have the required permissions as follows:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class CheckUserPermissionsAttribute : ActionFilterAttribute
{
//code goes here
// IF user is not authorized then ….
var viewResult = new ViewResult();
viewResult.ViewName = "~/Views/Errors/_Unauthorized.cshtml";
filterContext.Result = viewResult; }}
base.OnActionExecuting(filterContext);}}}
Now if a user access the SystemInfo
action method and he is not authorized he will get /_Unauthorized.cshtml
view, but if another user who is authorized and calls the SystemInfo
action method he will get the */_Unauthorized.cshtml*
view also.
Also if an authorized user access the SystemInfo
first, then a unauthorized user will be able to see call the action method and see the cached result? and even the current login username will be cached and the users will see others username on their sessions.
Can anyone advice how I can overcome this issue? Currently I changed the cache location to be on the client instead of server which temporary solve the issue, but I need to cache the action method on the server. I am thinking of passing the loginusername to my action method - any suggestions?
Thanks