Freigeben über


Cloud Tip #6-Encrypting the web.config with Visual Basic

One of the great things about Windows Azure is that it is a platform that is for the most part agnostic about what frameworks and languages you want to use. While I tend to do most of my demos in C# there is no reason we couldn’t use VB, PHP, Node.js, Java or any other language. In fact the developer story for the Microsoft Cloud is that if it runs on Windows it can run in Windows Azure. All you need is to configure the machine appropriately (more on that in another post). You can learn more about the tools by checking out the Tools section of the Windows Azure site.

For this CloudTip I got a request for how to do the encryption of the web.config but this time in VB. The logic is about the same, although I found that in VB I had to add a line to the configuration to save the new settings. The code for this in vb.net (adding to the global.asax file in the "Session_Start" subroutine…

 Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

    ' Code that runs when a new session is started 

    EncryptSection("appSettings")

End Sub

Private Sub EncryptSection(ByVal sSection As String)

    Dim config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Context.Request.ApplicationPath)

    Dim configSection As ConfigurationSection = config.GetSection(sSection)

    If configSection.SectionInformation.IsProtected = False Then

        configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")

        config.Save()

    End If

End Sub

If you have questions about Cloud that would make a great Cloud Tip topic send them to me at my email or comment on the post.

Thanks!

Comments

  • Anonymous
    May 02, 2012
    Wow that really helpful post. much to learn. I am Using Folder Lock for Cloud Encryption for 3 years and not seen any problem yet, now they are giving Free Online Backup and customer support is just like 24/7. Can anyone suggest me some other Software for Encryption.