Subscribe to Youtube channel

Encrypt web.Config sections using c# in asp.net

To give secuity to to your web application you need to make your applications secured you can encrypt the certain sections of web.config . To accomplish this task microsoft has provided library in the namespace System.Web.Configuration.
To Encrypt the web.config section you can use the following code
using System.Configuration.Provider;
using System.Configuration.Assemblies;
using System.Web.Configuration;

Configuration confi =  WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
  ConfigurationSection section = confi.ConnectionStrings;
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
To Decrypt the web.config section you can use the following code
using System.Configuration.Provider;
using System.Configuration.Assemblies;
using System.Web.Configuration;

Configuration confi =  WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
   ConfigurationSection section = confi.ConnectionStrings;
section.SectionInformation.UnprotectSection();
In above example I have encrypted the connectionString Section of the web.Config, similarly you can Encrypt and decrypt appsettings section of web.Config

Comments

Popular posts from this blog

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Implement Nlog in .Net core MVC application part 1

Devexpress Datebox date formatting in angular 6 with example

Disable backspace key using Jquery

Angular User Session Timeout example step by step

Restore the lost focus of Auto post back controls in asp.net update Panel control

How to Import CSV File and bind csv file data to gridview in asp.net using c#

Remove Owin from MVC 5 Application and use asp.net custom forms authentication

Clone a generic list in C# using extension method