merge -r 60814:60815
[mono.git] / mcs / class / System.Web / Test / standalone / configuration / save / save.aspx
1 <%@ Import Namespace="System.Web.Configuration" %>
2
3 <script runat="server" language="C#" >
4
5 protected void add_Click (object sender, EventArgs e)
6 {
7    try
8    {
9       Configuration config = 
10          WebConfigurationManager.OpenWebConfiguration(
11          Request.ApplicationPath);
12
13       ConnectionStringsSection sect = 
14          config.ConnectionStrings;            
15
16       if (sect.ConnectionStrings ["test"] != null) {
17                 lblResult.Text = "Connection string already exists for 'test'";
18       }
19       else {
20                 sect.ConnectionStrings.Add (new ConnectionStringSettings ("test", "test=foo;", "testProvider"));
21                 config.Save();
22                 lblResult.Text = "Connection string added";
23       }
24    }
25    catch (Exception ex)
26    {
27       lblResult.Text = "Exception: " + ex.Message;
28    }
29 //   lblResult.Text+="Connection String:" + 
30 //      ConfigurationManager.ConnectionStrings
31 //      ["test"].ConnectionString;
32 }
33
34 protected void remove_Click (object sender, EventArgs e)
35
36    try
37    {
38       Configuration config = 
39          WebConfigurationManager.OpenWebConfiguration(
40          Request.ApplicationPath);
41       ConnectionStringsSection sect = 
42          config.ConnectionStrings;
43       if (sect.ConnectionStrings ["test"] == null) {
44                 lblResult.Text = "connection string not present";
45         }
46         else {
47                 sect.ConnectionStrings.Remove ("test");
48                 config.Save();
49                 lblResult.Text = "connection string has been removed";
50         }       
51    }
52    catch (Exception ex)
53    {
54       lblResult.Text = "Exception: " + ex.Message;
55    }        
56 }    
57 </script>
58 <html>
59 <head>
60   <title>Adding and Removing Connection Strings</title>
61 </head>
62 <body>
63 <form id="form1" runat="server">
64 <div>
65   
66  <asp:Button ID="add" runat="server" Text="Add" OnClick="add_Click" />
67  <asp:Button ID="remove" runat="server" Text="Remove" OnClick="remove_Click" />
68  <br/><br/><br/>
69  <asp:Label ID="lblResult" runat="server"></asp:Label>
70 </div>
71 </form>
72 </body>
73 </html>