Creating a Web.config Editor - Part 2
page 3 of 4
by Jason N. Gaylord
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 21974/ 40

Section 2: Prepare Our Page
We will target the server node for this example. We will setup our page to include a few servers in a drop-down like the previous section demonstrated. We will add values of 'Server01', 'Server02', and 'Server03'. After adding these, our code should look like this:
EditConfig.aspx
**************************************************

1:   <%@ Page Language="vb" %>
2:   <%@ import Namespace="System" %>
3:   <%@ import Namespace="System.Xml" %>
4:   <script runat="server">
5:   
6:       Sub Page_Load(s as Object, e as EventArgs)
7:          Dim myConfig As New XmlDocument()
8:       
9:          myConfig.Load("C:\InetPub\wwwroot\web.config")
10:        
11:           If not isPostBack then
12:              Dim myCurrentValue as String
13:              Dim myListItem as ListItem
14:        
15:              myCurrentValue = myConfig.SelectSingleNode(
                  "configuration/appSettings/add[@key='conServer']
                  /@value").Value
16:              myListItem = node01.Items.FindByText(myCurrentValue)
17:        
18:              node01.SelectedIndex = node01.Items.IndexOf(myListItem)
19:           Else
20:             'We will save this for later!
21:           End If
22:        
23:        End Sub
24:    
25:    </script>
26:    <html>
27:    <head>
28:        <title>Web.config Editor</title>
29:    </head>
30:    <body>
31:        <form runat="server">
32:          <asp:Label id="title01" runat="server" text="Change Server:" />
33:          <asp:DropDownList id="node01" runat="server">
34:            <asp:ListItem Value="localhost" text="localhost" />
35:            <asp:ListItem Value="Server01" text="Server01" />
36:            <asp:ListItem Value="Server02" text="Server02" />
37:            <asp:ListItem Value="Server03" text="Server03" />
38:          </asp:DropDownList>
39:          <br />
40:        </form>
41:    </body>
42:    </html>

Notice how the SelectSingleNode option changed. We are now using a parameter to select which 'add' node we want to use. Think of this as a SELECT SQL statement. We are selecting the node where 'key' is equal to 'conServer'. The attribute of the node is assigned by using the ampersand(@) symbol. Then, the value you want to select is placed inside single quotes('). Finally, the entire statement is placed in between brackets([ and ]).

View Entire Article

User Comments

Title: Creating a Web.config Editor - Part 2   
Name: Kris Triyantio
Date: 2007-01-16 11:09:18 PM
Comment:
It's good, but i cannot save. it shown error message.
"access denied"
how can i handle that.

Thanks
Title: Creating a Web.config Editor - Part 2   
Name: Haroldo Carvalho
Date: 2006-02-01 9:58:14 AM
Comment:
Very good.
It realy helpped me.
Thanks

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 11:05:16 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search