0

I want to run a custom logic, before the page life-cycle, to decide what version of a cached page I want to serve to the user.

Example:

If the user is not logged, then I go to a cache dictionary, catch a version A of the page and serve to the user. Otherwise, if it's logged, then I'll see if I already cached a version of the page specific to that user. If a particular cached version doesn't exist yet, I'll let the life-cycle to complete and then I'll save it.

What I want is to manage different versions of a page and to determine whether a version or another should be served.

1 Answer 1

3

You should be able to use VaryByCustom for this, and just let ASP.NET worry about pulling the correct version of the page from the cache etc.

In the page itself...

<%@ OutputCache Duration="60" VaryByParam="None" VaryByCustom="LoggedInUser" %>

And in your Global.asax file...

public override string GetVaryByCustomString(HttpContext context, string custom)
{
    if (custom == "LoggedInUser")
    {
        if (UserIsLoggedIn())
        {
            return "LoggedInUser:" + GetUserNameOrSomeOtherUniquePerUserString();
        }
        else
        {
            return "LoggedInUser:NONE";
        }
    }
    return base.GetVaryByCustomString(context, custom);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.