WEBINAR:
On-Demand
Application Security Testing: An Integral Part of DevOps
Testing the Application
Now that you have created your class and set key values into your web.config file, it is time to test the application. Follow the steps below to create a user interface to display the values from the web.config file.
- Display Webform1.aspx in design mode.
- Set the pageLayout property to FlowLayout.
- Select Table, Insert, Table from the Visual Studio .NET menu.
- Create a table with 2 rows and 2 columns.
- Click OK.
- Click into the first cell of the first row in the table and double-click on the Label control in the toolbox.
- Set the Text property of this control to Site Name.
- Click into the second cell of the first row in the table and double-click on the Label control in the toolbox.
- Set the Name property to lblSiteName.
- Set the Text property of this control to an empty value.
- Click into the first cell of the second row in the table and double-click on the Label control in the toolbox.
- Set the Text property of this control to Connect String.
- Click into the second cell of the second row in the table and double-click on the Label control in the toolbox.
- Set the Name property to lblConnect.
- Set the Text property of this control to an empty value.
- Double click the form to display the Page_Load event procedure.
- Add the following code to the page.
You can test your AppConfig class by retrieving the properties and placing them into labels.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lblSiteName.Text = AppConfig.SiteName
lblConnect.Text = AppConfig.ConnectString
End Sub
Run the application and you should see the values you typed into the web.config file appear in the labels on the form.
With the application still running, modify the values in the web.config file and click the
Refresh button on your browser. After a couple of refreshes the values should automatically refresh with the new values.
Creating a configuration class has a lot of benefits when compared to just using the Application object by itself. The ability to have an IntelliSense listing of properties, automatic reload of values when the web.config file changes and having typed properties are just some of the advantages. While using this method requires a little more setup work, the payoff is well worth the effort.