
426
|
Chapter 20: web.config Reference
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
The following ASP.NET page retrieves the value set by the preceding code and
also retrieves a value set at the machine.config level:
<%@ Page Language="VB" %>
<html>
<head>
<script runat="server">
Sub Page_Load( )
Message1.Text &= _
ConfigurationSettings.AppSettings("machineConfigKey")
Message2.Text &= _
ConfigurationSettings.AppSettings("applicationConfigKey")
End Sub
</script>
</head>
<body>
<asp:label id="Message1" runat="server">Machine.Config setting: </
asp:label>
<br/>
<asp:label id="Message2" runat="server">Web.Config setting: </ asp:label>
</body>
</html>
Notes
As shown in the example, the <appSettings> element can be used separately from
the
<system.web> element and its children.
For security reasons, use caution when deciding what kinds of data to store using
the
<appSettings> element. Remember that while the ASP.NET runtime is set up
to prevent an application’s web.config file from being requested or read, this file
could still be vulnerable if the security of the web server were breached in some
other way. Thus, you should generally avoid storing sensitive information such as
usernames and passwords, or connection strings containing usernames and pass-
words, in the web.config file. A better, although still moderately vulnerable,
alternative ...