<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default_aspx" %>
Untitled Page
File: Default.aspx.vb
Imports System.Configuration
'Imports System.Web
'Imports System.Web.Security
Imports System.Web.Security
Partial Class Default_aspx
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
'Encrypt("DataProtectionConfigurationProvider")
'--or--
Decrypt()
'Encrypt("RSAProtectedConfigurationProvider")
' Decrypt()
'AddConnString()
'---retrieve the newly added string
Dim connect As String = _
ConfigurationManager.ConnectionStrings _
("PubsConnectionString").ConnectionString
Response.Write(connect)
End Sub
Public Sub Encrypt(ByVal protectionProvider As String)
Dim config As Configuration = _
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( _
Request.ApplicationPath)
Dim section As ConfigurationSection = config.Sections("connectionStrings")
If Not section.SectionInformation.IsProtected Then
section.SectionInformation.ProtectSection(protectionProvider)
config.Save()
End If
End Sub
Public Sub Decrypt()
Dim config As Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( _
Request.ApplicationPath)
Dim section As ConfigurationSection = config.Sections("connectionStrings")
section.SectionInformation.UnProtectSection()
config.Save()
End Sub
Public Sub AddConnString()
Dim config As Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( _
Request.ApplicationPath)
config.ConnectionStrings.ConnectionStrings.Add _
(New ConnectionStringSettings("NorthwindConnectionString", _
"server=localhost;database=northwind;integrated security=true"))
config.Save()
End Sub
End Class