The ASP.NET page architecture is extensible too. It's possible to create an intermediary page that sits between the base System.Web.UI.Page class, and the final ASPX page. By creating the following class:
public abstract class PageBase : System.Web.UI.Page
{
}
And having all of the ASPX pages inherits from:
public partial class MyPage : PageBase
{
}
It becomes easy to interject custom code specificly for your application. You can provide central access to objects, properties, or other information to all of the pages within your site. For instance, suppose we modified the PageBase class as:
public abstract class PageBase : System.Web.UI.Page
{
public string ApplicationName
{
get { return "My App"; }
}
public abstract string PageName
{
get;
}
}
In this example, the base class exposes the ApplicationName property to all of the pages that inherit from it, while requiring pages to implement the page name property. Our new ASPX page code-behind class now looks like the following.
public partial class MyPage : PageBase
{
public override string PageName
{
get { return "My Page"; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Response.Write(this.ApplicationName);
}
}
So the new code-behind class makes use of these properties of the PageBase class. As long as all of the pages from an ASP.NET application use this class, this class provides a central place to put global objects and information.