The example will check 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;
}
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment