<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="UpdateConfig" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Update Configuration</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Stop access to .XYZ Resources" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Text="Re-enable access to .XYZ Resources" OnClick="Button2_Click" />
<br />
<asp:Button ID="Button3" runat="server" Text="Encrypt connectionStrings" OnClick="Button3_Click" />
<br />
<asp:Button ID="Button5" runat="server" Text="Read Connection String" OnClick="Button5_Click" />
<br />
<asp:Button ID="Button4" runat="server" Text="Decrypt connectionStrings" OnClick="Button4_Click" />
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class UpdateConfig : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
string name = @"system.web/httpHandlers";
string path = "/";
Configuration appConfig = WebConfigurationManager.OpenWebConfiguration(path);
HttpHandlersSection section = (HttpHandlersSection)appConfig.GetSection(name);
HttpHandlerAction newHandler = new HttpHandlerAction(
"*.xyz", "System.Web.HttpForbiddenHandler", "*");
section.Handlers.Add(newHandler);
appConfig.Save();
}
protected void Button2_Click(object sender, EventArgs e)
{
string name = @"system.web/httpHandlers";
string path = "/";
Configuration appConfig = WebConfigurationManager.OpenWebConfiguration(path);
HttpHandlersSection section = (HttpHandlersSection)appConfig.GetSection(name);
section.Handlers.Remove("*", "*.xyz");
appConfig.Save();
}
protected void Button3_Click(object sender, EventArgs e)
{
string name = "connectionStrings";
string path = "/";
Configuration cfg = WebConfigurationManager.OpenWebConfiguration(path);
ConnectionStringsSection section;
section = (ConnectionStringsSection) cfg.GetSection(name);
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
cfg.Save();
}
protected void Button4_Click(object sender, EventArgs e)
{
string name = "connectionStrings";
string path = "/";
Configuration cfg = WebConfigurationManager.OpenWebConfiguration(path);
ConnectionStringsSection section;
section = (ConnectionStringsSection)cfg.GetSection(name);
section.SectionInformation.UnprotectSection();
cfg.Save();
}
protected void Button5_Click(object sender, EventArgs e)
{
Response.Write(WebConfigurationManager.ConnectionStrings["LocalNWind"].ConnectionString);
}
}
|