Check if web.config file encrypted or not.

This is an example of how to check if the web.config file is encrypted or not. Refer to this article to encrypt and decrypt the web.config file.

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

Code Behind

  private static string[] sectionName = { "connectionStrings", "appSettings", "system.web/authentication" };  
public static string[] SectionName
{
get
{
return sectionName;
}
set
{
sectionName = value;
}
}
/// <summary>
/// method to check if web config file is encrypted or not
/// </summary>
/// <returns></returns>
private bool CheckWebConfigIfEncrypt()
{
bool isEncrypt = false;
foreach (string a in SectionName)
{
Configuration config =
WebConfigurationManager.
OpenWebConfiguration("~" + HttpContext.Current.Request.ApplicationPath);
ConfigurationSection section =
config.GetSection(a);
if (section != null &&
section.SectionInformation.IsProtected)
isEncrypt = true;
else
{
return false;
}
}
return isEncrypt;
}

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

How to create DataGrid or GridView in JSP - Servlet

Control Webpart Visible/Enable using macro in Kentico