December 6, 2021 06:07 by
Peter
INITIAL CHAMBER
Open Visual Studio 2010 and create an empty website. Give a suitable name connectionstring_demo.
In Solution Explorer you get your empty website. Add a web form, SQL Database. Here are the steps:
For Web Form
connectionstring _demo (Your Empty Website) - Right Click, Add New Item, click Web Form. Name it connectionstring _demo.aspx.
For SQL Server Database
connectionstring _demo (Your Empty Website) - Right Click, Add New Item, click SQL Server Database. Add Database inside the App_Data_folder.
DESIGN CHAMBER
Now open your connectionstring _demo.aspx file, where we create our design for encrypting our Connection String.
connectionstring _demo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Press to Encrypt your Connection String" />
</div>
<p>
</p>
<p>
</p>
<p>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</p>
</form>
</body>
</html>
CODE CHAMBER:
Open your connectionstring _demo.aspx.cs and write some code so that our application starts working.
connectionstring _demo.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Configuration;
using System.Web.Configuration;
using System.Web.UI.WebControls;
public partial class _Default: System.Web.UI.Page
{
const string PROVIDER = "DataProtectionConfigurationProvider";
protected void Page_Load(object sender, EventArgs e)
{}
protected void Button1_Click(object sender, EventArgs e)
{
Configuration con = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConnectionStringsSection sect = con.ConnectionStrings;
sect.SectionInformation.ProtectSection(PROVIDER);
con.Save();
Label1.Text = "Your Connection String is Encrypted Now";
Label1.Text += "Your Connection String is:" + ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString;
}
}
OUTPUT CHAMBER
Open your Web.config File
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData>
<CipherValue>
// Your encrypted string
</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
</configuration>
Hope you liked this. Thank you for reading. Have a good day.
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.