130 likes | 253 Views
COMP6325 Advanced Web Technologies. Dr. Paul Walcott The University of the West Indies Session 4 – Building Enterprise-scale Web-based Applications – Part III : Configuring ASP.NET Spring 2009. Objectives. At the end of this session the student shall be able to:
E N D
COMP6325 Advanced Web Technologies Dr. Paul Walcott The University of the West Indies Session 4 – Building Enterprise-scale Web-based Applications – Part III : Configuring ASP.NET Spring 2009
Objectives • At the end of this session the student shall be able to: • Describe how ASP.NET applications are configured • Add a custom setting
An ASP.NET application comprises of (MacDonald 2007, p. 130):
The configuration files in ASP.NET… • Configure the way error messages are shown • Configure security settings • Allow users to add custom settings • And much, much more.
The advantage of these configuration files include (McDonald 2007): • They are never locked therefore can be updated at any time • They can be accessed easily • These files are easy to edit since they are in XML
The main configuration files are: • web.config • machine.config
What does the web.config file look like (McDonald 2007)? <xml version=“1.0” ?> <configuration> <configSections>…</configSections> <appSettings>… </appSettings <connectionStrings>… </connectionStrings> <system.web>… </system.web> <system.codedom>… </system.codedom> <system.webServer>…</system.webServer> </configuration>
Which sections of web.config are most important? • <appSettings> • Allows storage of custom settings • <connectionStrings> • Database connection information • <system.web> • The ASP.NET settings; for example <authentication> and <authorization>
Machine configuration files • Every web server starts with basic settings. These are defined in the machine.config and web.config files, located at: • c:\Windows\Microsoft.NET\Framework\v2.0.50727\Config • These settings affect the entire system • For application level settings use web.config • Which will be in the root of the virtual directory of the application
This is how you add a custom setting to the web.config file <appSettings> <add key”ImageFilesPath” value=“/pictures/images” /> </appSettings>
The custom setting can be queried using WebConfigurationManager using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Configuration; Public partial class QuerySettings : System.Web.UI.Page { protected void Page_Load() { lblMyImagesPath = “My images are in” + WebConfigurationManager.AppSettings[“ImageFilesPath”]; } }
Conclusion • In this session • The method used to configure ASP.NET was described
References MacDonald, M., “Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional”, Apress, Second Edition, 2007