<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-33832717</id><updated>2011-04-21T10:58:06.702-07:00</updated><title type='text'>mocsoft-web2</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mocsoft-web2.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/33832717/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mocsoft-web2.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mocsoft</name><uri>http://www.blogger.com/profile/06111363491304046579</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-33832717.post-115737920401903964</id><published>2006-09-04T07:12:00.000-07:00</published><updated>2006-09-04T07:13:24.023-07:00</updated><title type='text'>web.config Programmatically</title><content type='html'>The web.config file holds configuration details for your application such as; authenticaion methods, connection strings, web references, debug mode and many more. They can be configured here and accessed by all your asp.net pages. I find it handy to store certain values in here as well in the form of appsettings/keys. For example the following value can be stored/edited and accessed from any page in the same directory.&lt;br /&gt;&lt;br /&gt;*configuration*&lt;br /&gt;*appSettings*&lt;br /&gt;*add key="database" value="sqlserver" /*&lt;br /&gt;*/appSettings*&lt;br /&gt;*/configuration*&lt;br /&gt;&lt;br /&gt;Replace the * with a &lt;&gt; respectively&lt;br /&gt;&lt;br /&gt;This 'database' key can be accessed via the following statement in your code:&lt;br /&gt;&lt;br /&gt;System.Configuration.ConfigurationManager.AppSettings("database")&lt;br /&gt;&lt;br /&gt;The .Net Framework version 2.0 provides methods via the 'System.web.configuration' namespace to edit programmatically the web.config file. You have already seen how you can display the contents of the file. This in itself can be useful but even better than that we can edit dynamically the contents of key values and almost every other setting declared in the web.config file.&lt;br /&gt;&lt;br /&gt;The following code will edit the value held in the web.config file:&lt;br /&gt;&lt;br /&gt;Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)&lt;br /&gt;Dim section As AppSettingsSection = CType(config.GetSection("appSettings"), AppSettingsSection)&lt;br /&gt;section.Settings.Item("database").Value = "anotherDatabase"&lt;br /&gt;config.Save(ConfigurationSaveMode.Modified)&lt;br /&gt;&lt;br /&gt;Instead of writing the value held to the screen we are changing the value to read 'anotherDatabase' we are then using the config.save method from our configuration object to permenantly change this file.&lt;br /&gt;&lt;br /&gt;In general each section of the web.config file has its own set of objects in the configuration namespace to access and edit it. The previous example used the 'AppSettingsSection' to access the key value we had stored there.&lt;br /&gt;&lt;br /&gt;The code is slightly different when accessing the connectionStrings portion of the web.config file:&lt;br /&gt;&lt;br /&gt;Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)&lt;br /&gt;Dim section As New ConnectionStringSettings&lt;br /&gt;&lt;br /&gt;For Each section In config.ConnectionStrings.ConnectionStrings&lt;br /&gt;If section.Name = "yourDatabase" Then&lt;br /&gt;Response.Write(section.ConnectionString.ToString)&lt;br /&gt;End If&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;As you can see instead of using 'AppSettingsSection' we are now using the 'ConnectionStringsSettings' object. We also need a For/Next loop to access the particular connection string we are interested in. The reason we need a For/Next loop is down to the fact we can have several connection strings held in the one web.config file so we must go through these to find the one we want. Below is an example of how the connection string would be defined in the web.config file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*connectionStrings*&lt;br /&gt;*add name="yourDatabase" connectionString="Data Source=LOCALHOST;Initial Catalog=yourDB;User ID=user;Password=pass"&lt;br /&gt;providerName="System.Data.SqlClient" /*&lt;br /&gt;*/connectionStrings*&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To modify this setting rather than just read it, we can apply the config.save method to apply the changes.&lt;br /&gt;&lt;br /&gt;All other settings can be modified in the same way, if you have intellisense then I recommend scrolling through the various objects available under the 'System.web.configuration' namespace, this should have all you need to get going and creating very professional configuration of your web applications.&lt;br /&gt;&lt;br /&gt;Please feel free to discuss this post and if anyone has any neat implementations I would be very interested to hear about them.&lt;br /&gt;&lt;br /&gt;Thanks for reading.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33832717-115737920401903964?l=mocsoft-web2.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mocsoft-web2.blogspot.com/feeds/115737920401903964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=33832717&amp;postID=115737920401903964' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/33832717/posts/default/115737920401903964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/33832717/posts/default/115737920401903964'/><link rel='alternate' type='text/html' href='http://mocsoft-web2.blogspot.com/2006/09/webconfig-programmatically_04.html' title='web.config Programmatically'/><author><name>mocsoft</name><uri>http://www.blogger.com/profile/06111363491304046579</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-33832717.post-115736269989658274</id><published>2006-09-04T02:23:00.000-07:00</published><updated>2006-09-04T02:38:19.906-07:00</updated><title type='text'>Web 2</title><content type='html'>What do we mean by web 2? Well web 2 is what the web should have been long ago, in short I suppose it means the programmable web. There are many languages available to help you achieve a web 2 presence, one could argue they were about long ago in the shape of CGI, but I wont. Currently the most popular of these web server side languages are ASP.Net / PHP / JSP. I must confess I have little knowledge of PHP and even less of JSP and will not attempt to argue which of these technologies is the best. Instead I will stick with what I know ASP.Net.&lt;br /&gt;&lt;br /&gt;This blog is first and foremost a place for me to post useful pieces of code which will hopefully be of use to others as well. There will be no structure to any of the posts and they will only be described as random. However I will try my best to make each post universally understood by beginners and experts alike, I know how it is when your a beginner and these posts start assuming prior knowledge. I would also encourage some discussion on these posts and if anyone has any trouble with any of the code listed I will check the comments regularly and try to help.&lt;br /&gt;&lt;br /&gt;All the code listed here will be ASP.Net Visual Basic code, compliant with version 2.0 of the .Net Framework. If you want to buy a book on this technology I would independently recommend 'ASP.Net 2.0 Unleashed by Stephan Walther', a lot of the examples I provide here will probably be similar to what you will find in this book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33832717-115736269989658274?l=mocsoft-web2.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mocsoft-web2.blogspot.com/feeds/115736269989658274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=33832717&amp;postID=115736269989658274' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/33832717/posts/default/115736269989658274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/33832717/posts/default/115736269989658274'/><link rel='alternate' type='text/html' href='http://mocsoft-web2.blogspot.com/2006/09/web-2.html' title='Web 2'/><author><name>mocsoft</name><uri>http://www.blogger.com/profile/06111363491304046579</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
