p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 3.5 Basics (http://p2p.wrox.com/forumdisplay.php?f=351)
-   -   Change web config at runtime (http://p2p.wrox.com/showthread.php?t=72797)

louisa68 February 18th, 2009 05:37 AM

Change web config at runtime
 
Hi,

I have a setup page which appears the first time a client runs the web site which prompts for server, dbname etc which then sets the connection string & some app settings in the web.config. How do I reload these settings so the user can carry on to the main site without making the user reopen the site?
Thanks for any help
Louisa
[:confused:]

gbianchi February 18th, 2009 06:13 AM

Hi.

You usually don't ask about databases and that type of things to a web user. Why do you want to do that?
If you are giving a complete website to the user, you will have to instruct him on how to modify config.web.
The only thing you can do to change it, If I'm not confused, is restart IIS...

louisa68 February 18th, 2009 06:39 AM

Hi,
The website will be installed on the webserver by the client's IT department & I am tryng to make it as seamless as possible so that when they have entered the info it will go straight to the site so they can verify that it works.

Imar February 18th, 2009 02:48 PM

Hi there,

You may want to take a look here: http://www.odetocode.com/Articles/418.aspx

It's a nice introduction in working with the configuration API to write to config files.

Hope this helps,

Imaer

zeronexxx February 18th, 2009 04:21 PM

Quote:

Originally Posted by louisa68 (Post 235070)
Hi,

I have a setup page which appears the first time a client runs the web site which prompts for server, dbname etc which then sets the connection string & some app settings in the web.config. How do I reload these settings so the user can carry on to the main site without making the user reopen the site?
Thanks for any help
Louisa
[:confused:]


To me your approach is wrong if I have understood your question correctly. In above scenario you would not use web.config for storing the website configuration rather an XML File.

You will ask the user for the settings and store them in the XML file and load them back into Memory(cache) and you will use it from Memory there after again.

You can also make changes and save it to the XML configuration file again at runtime without need to of WebServer or App Pool restart.

Regards

louisa68 February 19th, 2009 10:20 AM

Quote:

Originally Posted by Imar (Post 235105)
Hi there,

You may want to take a look here: http://www.odetocode.com/Articles/418.aspx

It's a nice introduction in working with the configuration API to write to config files.

Hope this helps,

Imaer

Hi, I looked at this and it said "Another caveat is that the ASP.NET runtime watches web.config and will restart the web application when a change occurs. Specifically, the runtime will create a new instance of your application inside of a new AppDomain anytime you write to web.config. A restart can have a performance impact, so writing to web.config should not occur often." but my website doesn't restart as if it did it would pick up my changes and not show the setup page again,
I have the following code in after the changes are saved to the web config but they don't seem to help.
System.Configuration.ConfigurationManager.RefreshS ection(.ConnectionStrings.SectionInformation.Name)
System.Configuration.ConfigurationManager.RefreshS ection(.AppSettings.SectionInformation.Name)

If I exist & go back into the site then it doesn't show the setup page again as the changes are being saved correctly, I just want to not have to do it manually, any other ideas out there?
[:confused:]

louisa68 February 19th, 2009 10:22 AM

Quote:

Originally Posted by zeronexxx (Post 235108)
To me your approach is wrong if I have understood your question correctly. In above scenario you would not use web.config for storing the website configuration rather an XML File.

You will ask the user for the settings and store them in the XML file and load them back into Memory(cache) and you will use it from Memory there after again.

You can also make changes and save it to the XML configuration file again at runtime without need to of WebServer or App Pool restart.

Regards


Hi,

When I say client I'm not talking about each individual user I am talking about an organisation as a whole, this setup only needs to happen once per site and never changes again.

Imar February 19th, 2009 12:02 PM

Quote:

I just want to not have to do it manually, any other ideas out there?
Not sure what you're asking it. It seems to work fine but then what?

Imar

zeronexxx February 19th, 2009 04:54 PM

Quote:

Originally Posted by louisa68 (Post 235153)
Hi,

When I say client I'm not talking about each individual user I am talking about an organisation as a whole, this setup only needs to happen once per site and never changes again.


Hi Everyone

Can someone please correct me if I am wrong in the above post of mine? I mean my approach.

And Even if you store the configuration in an other XML file other web.config.
You will only ask the user if the configuration is missing from Memory(cache) and XML configuration file as also missing, which will be true only for the first user.


Some people tell me that I need help some people ...........................

gbianchi February 19th, 2009 08:07 PM

Quote:

Originally Posted by louisa68 (Post 235153)
Hi,

When I say client I'm not talking about each individual user I am talking about an organisation as a whole, this setup only needs to happen once per site and never changes again.

Then you will have a sort of specialized user (it has to at least set up a IIS!), so why not just add a help file to tell the user what to update and where and you forget about all this problems?
I love configurations UI (always do everything you can for the user), but in this case this seems to be rather unnecesary...


All times are GMT -4. The time now is 04:16 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.