
304
|
Chapter 14: The HttpContext Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Parameters
Object
An object containing the keys and values in the configuration sections speci-
fied by
name. This object is often of a type derived from
NameValueCollection.
name
The name of the section to retrieve.
Example
The example shows how you can use the GetAppConfig method to retrieve all
items in a configuration by setting from the web.config or machine.config XML
configuration file. While GetAppConfig returns an Object, you must cast the
returned object to the NameValueCollection-derived type defined in the configu-
ration section to actually access the information. This method is static, so an
instance of the
HttpContext class is not required.
Sub Page_Load( )
Dim i As Integer
Dim nv As NameValueCollection
nv = CType(HttpContext.GetAppConfig("appSettings"), _
NameValueCollection)
For i = 0 To nv.Count - 1
Response.Write(nv.GetKey(i) & " = " & nv(i) & "<br/>")
Next
End Sub
Notes
Generally you will not use GetAppConfig to get the appSettings section from the
configuration file. It is much easier and safer to use ConfigurationSettings.AppSet-
tings to get at these values. This method, however, can be used to get information
from custom configuration sections.
GetConfig
Object = Context.GetConfig(ByVal name As String)
Returns the collection of key/value ...