Decrypt web.config file - asp.net

This is an example of how to decrypt a web.config file in asp.net. You can refer to this post on how to encrypt web config file.

The example will decrypt web config file for 3 section which is ConnectionString, AppSetting, and system.web/authentication.

Front End .aspx code

  <br />  
This is button to decrypt web config.<br />
<asp:Button ID="Button2" runat="server" Text="Decrypt Web Config" OnClick="Button2_Click" />


Code behind

  private static string[] sectionName = { "connectionStrings", "appSettings", "system.web/authentication" };  
public static string[] SectionName
{
get
{
return sectionName;
}
set
{
sectionName = value;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//decrypt
UnProtectSection();
}
/// <summary>
/// Decrypted web config file for certain section
/// </summary>
/// <param name="sectionName"></param>
private void UnProtectSection()
{
foreach (string a in SectionName)
{
Configuration config =
WebConfigurationManager.
OpenWebConfiguration("~/");
ConfigurationSection section =
config.GetSection(a);
if (section != null &&
section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
}
}
}

Output





Popular posts from this blog

How to create zip file to download in JSP- Servlet

How to create DataGrid or GridView in JSP - Servlet

Pinging in ASP.NET Example