Name
GetAppConfig
Synopsis
Object = HttpContext.GetAppConfig(ByVal name As String)
Returns
the collection of key/value pairs that are contained in the
configuration specified by the name
argument.
Parameters
-
Object An object containing the keys and values in the configuration sections specified 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 configuration
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 SubNotes
Generally you will not use GetAppConfig to get the
appSettings section from the configuration file.
It is much easier and safer to use ConfigurationSettings.AppSettings
to get at these values. This method, however, can be used to get
information from custom configuration sections.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access