Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

How to programmaticaly change the web.config?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PSiegmann@mail.nu - 22 Dec 2007 04:18 GMT
Hello group..

Is there a way to change web.config entries at runtime? I haven't
found a class for that.
I have around 20 entries in the web.config, and I want a add a
configuration menu into my app, so that the administrator can change
some of the settings, without editing the web.config directly with a
text editor.
Riki - 22 Dec 2007 08:57 GMT
> Hello group..
>
[quoted text clipped - 4 lines]
> some of the settings, without editing the web.config directly with a
> text editor.

In ASP.NET 2.0, you can use the System.Configuration classes, see
http://www.codeproject.com/KB/dotnet/mysteriesofconfiguration.aspx

You can also write to the web.config file in the same way as you would to
any XML file, something like (in VB.NET):
-----------------------------
Try
   ' Open web.config file
   Dim doc As New XmlDocument()
   doc.Load(Server.MapPath("web.config"))

   Dim strSel As String
   ' Use an XPath query to look up the user element in this configuration
having
   ' a matching "name" attribute
   strSel =
"/configuration/system.web/authentication/forms/credentials/user[@name='" &
strUserName & "']"
   Dim node As XmlNode = doc.SelectSingleNode(strSel)
   ' Modify the element
   Dim element As XmlElement = CType(node,XmlElement)
   element.SetAttribute("password",strHash)

   ' Save the configuration
   doc.Save(Server.MapPath("web.config"))
Catch ex As Exception
   Trace.Warn(ex.ToString())
End Try
------------------------------
Keep in mind that changing web.config may cause your application to restart,
thereby losing the session information for all users.

Signature

Riki

Mark Stevens - 22 Dec 2007 09:02 GMT
Is this any use http://odetocode.com/Articles/418.aspx

Regards,
Mark

>Hello group..
>
[quoted text clipped - 4 lines]
>some of the settings, without editing the web.config directly with a
>text editor.
Signature

      |\      _,,,---,,_          A picture used to be worth a
ZZZzzz /,`.-'`'    -.  ;-;;,       thousand words - then along
     |,4-  ) )-,_. ,\ (  `'-'     came television!
    '---''(_/--'  `-'\_)          

Mark Stevens  (mark at thepcsite fullstop co fullstop uk)

Eliyahu Goldin - 23 Dec 2007 10:35 GMT
The way to go is to put all your setting that can change in a separate file.

Put this line in the <configuration> section on web.config

<appSettings file="MySettings.xml"/>

Having done that, you can access parameteres in MySettings.xml via
ConfigurationManager.AppSettings.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Hello group..
>
[quoted text clipped - 4 lines]
> some of the settings, without editing the web.config directly with a
> text editor.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.