Presentation is loading. Please wait.

Presentation is loading. Please wait.

Delivering Excellence in Software Engineering ® 2006. EPAM Systems. All rights reserved. Configuration.

Similar presentations


Presentation on theme: "Delivering Excellence in Software Engineering ® 2006. EPAM Systems. All rights reserved. Configuration."— Presentation transcript:

1 Delivering Excellence in Software Engineering ® 2006. EPAM Systems. All rights reserved. Configuration

2 ® 2006. EPAM Systems. All rights reserved. Configuring ASP.NET ASP.NET is configured via an extensible configuration file format –ASP.NET configuration controlled using an XML file named web.config –Typically located at the top-level of the virtual root directory –ASP.NET configuration happens post-IIS metabase web.config

3 ® 2006. EPAM Systems. All rights reserved. ElementPurpose Specify the client authentication mode to use Allow or deny users or roles access Specify browser capabilities based on user agent Define client targets Control page compilation and assembly references Control error page display and define custom error pages Set the request and response encoding Add or remove HTTP handlers Add or remove HTTP modules Control aspects of HTTP request processing Specify impersonation for this application Control the validation and decryption key Set defaults for page attributes globally Control the behavior of the worker process Define trust levels with associated policy files Control session state Enable application-wide tracing Select which trust level to use Specify web service protocols and extensions Add application-specific data elements Top-level configuration elements available in web.config

4 ® 2006. EPAM Systems. All rights reserved. Hierarchical file layout Configuration files for ASP.NET can be in one of 4 places: –machine –site –application –subdirectory Configuration settings are applied hierarchically –Root machine.config file in.NET installation directory is applied first –Any web.config file in the site directory is applied next –The web.config file at the root of the virtual directory is applied next –Any web.config files found in sub-directories under the virtual root are applied last

5 ® 2006. EPAM Systems. All rights reserved. Hierarchy of configuration files

6 ® 2006. EPAM Systems. All rights reserved. Cumulative configuration example

7 ® 2006. EPAM Systems. All rights reserved. Location element Location element can be used to apply settings to specific files or subdirectories from a top-level configuration file –Sometimes preferable to spreading web.config files throughout your directory structure –Specify a named path and configuration settings to apply web.config

8 ® 2006. EPAM Systems. All rights reserved. Element Placement Some elements are restricted in where they can be applied –Elements that cannot be applied at the subdirectory level include authentication sessionState trust httpModules (do not take effect) –The processModel element can only occur in machine.config

9 ® 2006. EPAM Systems. All rights reserved. Impact of configuration changes Any change to an application's web.config file will restart that application –its application domain will be unloaded and re-created –any in-process state will be lost (session, application, etc.)

10 ® 2006. EPAM Systems. All rights reserved. Configuration Data Custom application configuration data may be stored in web.config and accessed via static property accessors –Ideal place to store DSN or other global settings that may need to be changed at deployment –The appSettings element in the web.config file supports adding key/value pairs that can be retrieved from within an application at runtime –The value of a key is retrieved through the Context.GetConfig() method of the HttpContext class, or through the ConfigurationSettings.AppSettings property

11 ® 2006. EPAM Systems. All rights reserved. Accessing configuration data using static property accessors <add key="DSN" value="server=.;trusted_connection=yes;database=test"/> web.config public void Page_Load(object src, EventArgs e) { string dsn = ConfigurationSettings.AppSettings["DSN“]; // use dsn here } somepage.aspx

12 ® 2006. EPAM Systems. All rights reserved. Process model configuration The lifetime of the aspnet_wp.exe worker process (IIS 5) is configurable –aspnet_isapi.dll reads the processModel configuration section in global machine.config file –Each worker process used to service unlimited requests by default In IIS 6 the worker process w3wp.exe can be controlled per application pool –processModel element ignored –settings drawn from metabase.xml

13 ® 2006. EPAM Systems. All rights reserved. Limiting worker process usage Lifetime of worker process can be limited by several factors –Total lifetime of process –Total time idle –Number of requests –Amount of memory consumed –When limit is reached, process is replaced with a new instance –New requests queued to new process –Old process handles pending requests before shutting down

14 ® 2006. EPAM Systems. All rights reserved. <processModel enable="true" timeout="Infinite" idleTimeout="Infinite" shutdownTimeout="0:00:05" requestLimit="Infinite" requestQueueLimit="5000" restartQueueLimit="10" memoryLimit="60" webGarden="false" cpuMask="0xffffffff" userName="MACHINE" password="AutoGenerate" logLevel="Errors" clientConnectedCheck="0:00:05" comAuthenticationLevel="Connect" comImpersonationLevel="Impersonate"/>...... processModel element in machine.config (IIS 5)

15 ® 2006. EPAM Systems. All rights reserved. Application pool properties in metabase.xml (IIS 6)

16 ® 2006. EPAM Systems. All rights reserved. Referencing GAC Assemblies To add a reference to an assembly deployed in the GAC –Use the assemblies element with an add sub-element <add assembly="util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a77a5c561934e089" />

17 ® 2006. EPAM Systems. All rights reserved. Configuration file extensibility Configuration files are divided into two distinct sections –The configuration section handlers Contains classes that parse specific sub-sections of the data portion of the file –The configuration data Contains data parsed by the configuration section handlers

18 ® 2006. EPAM Systems. All rights reserved. configuration section handlers in machine.config

19 ® 2006. EPAM Systems. All rights reserved. Building custom configuration section handlers You can build your own configuration section handlers –Useful if appSettings element is not sufficient –Create a class that implements IConfigurationSectionHandler –Define a class/struct to store the configuration data –Read the incoming XML in Create() and return a reference to the configuration structure –Install the handler by adding it to the configSections element public interface IConfigurationSectionHandler { object Create(object parent, object input, XmlNode node); }

20 ® 2006. EPAM Systems. All rights reserved. Leveraging NameValueFileSectionHandler NameValueFileSectionHandler can be used to define generic configuration sections with name/value pairs –Lets you define a custom section without going to the trouble of building your own custom class <section name="myGroup" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

21 ® 2006. EPAM Systems. All rights reserved. Accessing custom configuration section using NameValueFileSectionHandler protected void Page_Load(object src, EventArgs e) { NameValueCollection set; set = ConfigurationSettings.GetConfig("myGroup") as NameValueCollection; // use set here (like set["font"], // set["verticalWidth"], etc. }

22 ® 2006. EPAM Systems. All rights reserved. Summary ASP.NET applications are configured through web.config files web.config files store configuration settings in an extensible XML format Static application data can be stored and retrieved in web.config files processModel controls lifetime and properties of ASP.NET process configuration files are extensible

23 Delivering Excellence in Software Engineering ® 2006. EPAM Systems. All rights reserved. For more information, please contact: Uladzimir Tsikhon Software Engineering Manager, Belarus Recourse Development Department EPAM Systems, Inc. Belarus, Minsk Phone: +375(17) 2101662 ext 1756 Fax: +375(17) 2101168 Email: uladzimir_tsikhon@epam.com http://www.epam.com


Download ppt "Delivering Excellence in Software Engineering ® 2006. EPAM Systems. All rights reserved. Configuration."

Similar presentations


Ads by Google