Encrypt and decrypt web.config

Abone Ol İçerikleri Kaçırma
tarafından 12 Şubat 2013 tarihinde Digerleri kategorisine yazıldı.

using System;

using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;

public partial class _Default : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
ProtectSection(“connectionStrings”, “DataProtectionConfigurationProvider”);
ProtectSection(“appSettings”, “RSAProtectedConfigurationProvider”);
}

private void ProtectSection(string strSectionName, string provider)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

ConfigurationSection section = config.GetSection(strSectionName);

if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}

}

private void UnProtectSection(string strSectionName)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

ConfigurationSection section = config.GetSection(strSectionName);

if (section != null && section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
}
}

protected void Button2_Click(object sender, EventArgs e)
{
UnProtectSection(“connectionStrings”);
UnProtectSection(“appSettings”);
}

}

0 0 votes
Makaleyi Oylamayı Unutmayın !

Bu yazı blog üzerinde Tayfun DEĞER tarafından paylaşılmıştır. 2009 yılında açılan blog kısa zaman içerisinde büyük bir izleyici kitlesine sahip olmuştur. Tayfun DEĞER danışmanlık ve eğitimler vermektedir. vExpert 2013-2019, VCP4/5/6, VCP5-DT, VCP-Cloud ve MCSE sertifikalarına sahiptir.Twitter 'dan @tayfundeger veya RSS ile sitedeki değişiklikleri takip edebilirsiniz.

Subscribe
Bildir
guest

0 Yorum
Inline Feedbacks
View all comments