R – Dynamic nested master pages, shared properties

asp.netmaster-pages

I have a base master page that specifies the main layout template of a website. It also handles some logic that changes tabs depending on the section, and also sets page meta information.

I'm dynamically loading nested master pages by looking at the querystring, loading up a record from the database, and setting the nested master page dynamically based on a value found in that record. I need to load dynamic nested master pages for layout and functional differences.

There is additional information in that record that I want to use in the base master page and in the dynamically loaded master page so I can avoid additional database calls.

Currently, I have set up a class that inherits MasterPage to act as the base class for the base master page. I have a shared (static) property that holds the object representing the database call that I want to share between the base master page and the nested, dynamically called master page.

It works, but it seems a little ugly. Are there any other better solutions?

Best Answer

You could always pass the record in the HttpContext.Items collection. Once it is in the Items collection it is available to every thing that can reach the HttpContext for the duration of the request.

Related Topic