Saturday, 3 October 2015

Check web config file either encrypt or not.

Leave a Comment
This is example how to check if web.config file is encrypt or not. refer this article to encrypt and decrypt web config file.

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
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

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.