Introduction
This article explains about how to encrypt and Decrypt web.config file in web application. In web Application Sometime we put come confidential information in configuration section like (appsetting, Connectionstring)
Technologies
.NET Framework 2.0 or later
Language
C#
Prerequisite
Visual Studio 2005 and Later
Implementation
Following namespace will added
using System.Web.Configuration;
Step-1
Take two buttons in Aspx Page like
Copy-Past following code in aspx page
{codecitation class="brush:html; gutter: true;" width="650px"}
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Untitled Pagetitle>
head>
onclick="btnEncrypt_Click" /> runat="server" Text="Dycrypt" onclick="btnDyscrypt_Click" />
div>
form>
body>
html> {/codecitation}
Step-2
Copy-past following two method in code file (aspx.cs) of Page
{codecitation class="brush: csharp; gutter: true;" width="650px"}
protected void btnEncrypt_Click(object sender, EventArgs e)
{
try
{
Configuration confg = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection confStrSect = confg.GetSection("connectionStrings");
if (confStrSect != null)
{
confStrSect.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
confg.Save();
}
}
catch (Exception ex)
{
throw ex;
}
}
protected void btnDyscrypt_Click(object sender, EventArgs e)
{
try
{
Configuration confg = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection confStrSect = confg.ConnectionStrings; if (confStrSect != null && confStrSect.SectionInformation.IsProtected)
{
confStrSect.SectionInformation.UnprotectSection();
confg.Save();
}
}
catch (Exception ex)
{
}
} {/codecitation}
Conclusion We can easily encrypt web.config file at client place for some confidential information.
Enjoy!!!!!!
| About the Author |
 | | Kirti Darji | P.G.D.C.A, M.SC(Computer Science) 3+ YEAR EXPERIENCE Visual C#.net and VB.net Windows and Web base Application
Expertise :C#.net, VB.Net,ASP.net,SQL Server, MS Access,aJAX, JavaScript,CSS,HTML,XML,N TIRE ARCHITECTURE,oOPS,Web Services,Core Ajax,visual Source safe,IIS
Occupation :SR. Software Developer Company : MADHUVAN INFO TECH PVT.LTD Location :AHMADABAD
|
|
|