<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>BenkoBLOG : VB</title><link>http://blogs.msdn.com/benko/archive/tags/VB/default.aspx</link><description>Tags: VB</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Encrypting the Web.config in VB</title><link>http://blogs.msdn.com/benko/archive/2008/04/16/encrypting-the-web-config-in-vb.aspx</link><pubDate>Wed, 16 Apr 2008 20:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8399267</guid><dc:creator>benko</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/benko/comments/8399267.aspx</comments><wfw:commentRss>http://blogs.msdn.com/benko/commentrss.aspx?PostID=8399267</wfw:commentRss><wfw:comment>http://blogs.msdn.com/benko/rsscomments.aspx?PostID=8399267</wfw:comment><description>&lt;P&gt;I got a request for how to do the encryption of the web.config but this time in VB, so I thought I'd post it here on the blog as well. 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.&amp;nbsp; The code for this in vb.net (adding to the global.asax file in the "Session_Start" subroutine:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;Sub&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt; Session_Start(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; EventArgs) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;' Code that runs when a new session is started 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;EncryptSection(&lt;SPAN style="COLOR: #a31515"&gt;"appSettings"&lt;/SPAN&gt;) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;End&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt; &lt;SPAN style="COLOR: blue"&gt;Sub 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;Private&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; EncryptSection(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sSection &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;String&lt;/SPAN&gt;) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; config &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Context.Request.ApplicationPath) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; configSection &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; ConfigurationSection = config.GetSection(sSection) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; configSection.SectionInformation.IsProtected = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;configSection.SectionInformation.ProtectSection(&lt;SPAN style="COLOR: #a31515"&gt;"DataProtectionConfigurationProvider"&lt;/SPAN&gt;) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;config.Save() 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt;End&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: " lucida console?; mso-bidi-font-family: ?Times New Roman?; mso-no-proof: 14.0pt? mso-bidi-font-size: yes;&gt; &lt;SPAN style="COLOR: blue"&gt;Sub 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8399267" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/benko/archive/tags/Code/default.aspx">Code</category><category domain="http://blogs.msdn.com/benko/archive/tags/VB/default.aspx">VB</category><category domain="http://blogs.msdn.com/benko/archive/tags/Security/default.aspx">Security</category></item></channel></rss>