3.4 Additional Settings


The best way to familiarize yourself with the various settings available for ASP.NET applications is to open the machine.config file on your system and peruse the elements. Each element is carefully documented with available child elements and attributes, and many examples are included. It is also in this file that you can find out what the defaults are for all of the ASP.NET applications on your machine. We discuss some of the additional elements in later chapters, where they are more directly relevant to the topic at hand.

As you begin to develop ASP.NET applications, you should be aware of two additional configuration elements: the assemblies element and the pages element. If you find you are using the @Assembly directive to add a reference to a GAC-deployed assembly to several pages in an application, you can instead reference that assembly once globally in the application's web.config file using the assemblies element. For example, suppose you have built a utilities assembly called Util that contains a number of utility classes used throughout the applications on your server. If you decide to deploy this assembly in the GAC, you can add an implicit reference to the assembly to all pages in your application by adding it to the assemblies element in your root web.config file, as shown in Listing 3-7.

Listing 3-7 Adding an Application-wide Reference to a GAC-Deployed Assembly
 <configuration>   <! ... >   <system.web>   <compilation>     <assemblies>       <add assembly="Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a77a5c561934e089" />     </assemblies>   </compilation>   </system.web> </configuration> 

Similarly, if you find that you are repeating the same @Page directives for many of the pages in your application, you can instead use the pages element in your application-wide web.config file to change the default for many of the @Page directive attributes. For example, suppose you wanted to disable view state for all pages in your application by default. Listing 3-8 shows the configuration file necessary to do this.

Listing 3-8 Using the pages Element
 <configuration>   <! ... >   <system.web>   <pages enableViewState='false' />   </system.web> </configuration> 


Essential ASP.NET With Examples in C#
Essential ASP.NET With Examples in C#
ISBN: 0201760401
EAN: 2147483647
Year: 2003
Pages: 94
Authors: Fritz Onion

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net