Sunday, June 08, 2008

Cool things in web.config of ASP.NET 2.0

Using web.config in ASP.NET 2.0, you can do many things which apply in your whole web application.

Setting common base class for pages:
You can set base class of all the pages. The code will look as below:

<system.web>
<pages pageBaseType=”MySite.UI.WebSitePageBase” />
</system.web>

Using this, pages in your application will not inherit System.Web.UI.Page class. Instead all will inherit MySite.UI.WebSitePageBase class.
In your page you case specifically inherit from System.Web.UI.Page class. If not specified then by default, pages will inherit MySite.UI.WebSitePageBase class.

Importing namespace for pages:
You can also import the namespace for every page.
<system.web>
<pages>
<imports>
<add namespace=” MySite.UI” />
</imports>
</pages>
</system.web>


Registering custom control:
You can register custom controls/tag prefixes for whole web site.
<configuration>
<system.web>
<pages>
<registerTagPrefixes>
<add tagPrefix="ashish" namespace="Ashish.UI.MyControls"/>
</registerTagPrefixes>
</pages>
</system.web>
</configuration>

No comments:

Post a Comment