I wonder if you can help me understand a piece of code a little more. I'm currently working my way through an MCTS Self Paced Training Kit (70-505, Chapter 5, Lesson 6). This particular lesson teaches you about securing connection string data. It explains the basic premise, and asks you to 'copy and paste' the following code into Visual Studios to demonstrate it. I do like to understand why a particular piece of code works before I move on, but for the life of me I can't quite see it.
Here is the code: (a reference is also needed to System.Configuration in the properties)
Public Class Form1
Private Sub EncryptConnectionString()
' Get the configuration file
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
' Create the provider name
Dim provider As String = "DataProtectionConfigurationProvider"
' Encrypt the ConnectionStrings
Dim connStrings As ConfigurationSection = config.ConnectionStrings
connStrings.SectionInformation.ForceSave = True
I understand that this code:
a] creates the configuration file
b] puts the connection string in the config file
c] encrypts the section with connection string in it
What I'd like to know is how the code actually infers this! I can see that:
connStrings.SectionInformation.ProtectSection(prov ider) encrypts the section named DataProtectionConfigurationProvider.
But I can't understand how the code that 'gets the configuration file' works, and how the application would know how to search that file for it, as opposed to within the compiled data - there seems to be no method called that instructs the application to do that!
As they say.... ask a stupid question and you'll feel a fool for five minutes....
Thanks very much in advance!