R – Base Page or Base Master Page or Nested Masters

asp.netcode-behindmaster-pages

I've got a site with two master pages: one for one-column layout and one for two-column layout. These are nested within a master page that provides a common header and footer.

I have functionality that I want each of the content pages to have; should I:

  • create a page base class and inherit that inside my content pages, or
  • create a master page base class and inherit that inside one of my levels of nested master page?

Ultimately I want the content pages to have access to a connection object and to a configuration object that I want to be instantiated as each page loads.

Best Answer

Master pages should only be used for layouts in my opinion.

If you want to be doing work such as creating connections, do that in a base class.

However, it is important that you not create a database connection at the start of your page, and close it at the end. You should be opening and closing connections as you run individual queries. This allows connection pooling to work efficiently.

Additionally, I would not be putting a connection of any type in the page itself, as you want to separate your functionality as much as possible from the layout.

Related Topic