Base Page or Base Master Page or Nested Masters?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 03:48:34

问题


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.


回答1:


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.




回答2:


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.

Base page is a prime target for this.




回答3:


I typically use a base page that contains a number of features that ease the creation of content pages. See http://dotnetslackers.com/articles/aspnet/Four-Helpful-Features-to-Add-to-Your-Base-Page-Class.aspx for some examples of useful BasePage features.



来源:https://stackoverflow.com/questions/738777/base-page-or-base-master-page-or-nested-masters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!