Output Caching - GetVaryByCustomString based on the value set in PageLoad ()

I am using ASP.net output caching and want to implement its GetVaryByCustomString () version. However, I ran into an issue where the cache is based on the value given in the PageLoad () of the page.

When loading Default.aspx, the version of USER CONTROL that I would like to show is based on the URL that the database request must go through.

www.website.com/apples will load, and in the code behind the page, I'll query the database to retrieve the values ​​I want.

Can output caching be used or will I need to implement my own options.

Is it possible to query the database earlier in the page lifecycle so that when GetVaryByCustomString is executed, the variable is already set?

0


source to share


1 answer


I've moved the variable assignment code to the Page_PreInit method, which seems to be executed before GetVaryByCustomString ().



+2


source







All Articles