Name
GetConfig
Synopsis
Object = Context.GetConfig(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 GetConfig method to retrieve
all items in a configuration 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.
Sub Page_Load( )
Dim i As Integer
Dim nv As NameValueCollection
nv = CType(Context.GetConfig("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 GetConfig to get the
appSettings section from the configuration file.
It is much easier and safer to use ConfigurationSettings.AppSettings
to get 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