Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

using System.Configuration.ConfigurationManager
wiglebot
#1 Posted : Friday, 5 June 2009 4:49:18 PM(UTC)
Rank: Member

Joined: 30/05/2009(UTC)
Posts: 3

Is there a reason that I am missing for the WebConfigController and util.cs to open and parses the web.config manually.

The web.cong is accessible from the System.Configuration.ConfigurationManager
The connection string can accessed via:
Code:
System.Configuration.ConfigurationManager.ConnectionStrings[Constants.SQL_SERVER_CN_STRING_NAME].ConnectionString;


Then there is System.Configuration.ConfigurationManager.GetSection("The other stuff")


Also to get the GSP.config path is a big function so I nested in appsettings so it is accessed via:
Code:
return System.Configuration.ConfigurationSettings.AppSettings["GalleryServerProPath"].ToString();

Then the subpath is not used.

You may have your reasons, but if not......

thanks,
Roger Martin
#2 Posted : Saturday, 6 June 2009 1:23:28 PM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,300
Location: Fort Atkinson, WI

If you dig a little digger, you'll notice that I use the WebConfigController only when I need to write to web.config. That is, during the install and upgrade wizards. One cannot use the Configuration API to write to web.config (or galleryserverpro.config) in medium trust scenarios.

There is a long story here. A few years ago I worked with MS to figure out how to get their Configuration API able to update web.config and galleryserverpro.config in medium trust. Both of these files are contained within the web application directory, so there isn't a good reason why it cannot be done. After all, the API was released with .NET 2.0 to much fanfare as the best way to handle configuration settings. In the end, they said it can't be done.

I submitted a feature request on MS Connect to make it so it *can* be done. They ended up closing it out and saying that the configuration settings are not designed to be updated in a live web application and that this feature was not in scope. I think they came to realize the limitations of their configuration architecture and started backing away from it.

So, as a workaround, if I want to update these files in medium trust, I have to manually do it. Hence the parsing of these files that you see.

The other big downside with the configuration system is that the app must restart each time a setting is changed. Not cool.

At some point I may move away from this architecture, but GSP has a lot invested in it at this point so it is not a high priority.

That is fine if you want to create an app setting called GalleryServerProPath, but that means you end up defining the path in two places (the other being the line <galleryServerPro configSource="gs\config\galleryserverpro.config" />). I want to make GSP easy to install and maintain, so if I can write a function that saves the administrator from having to define a path twice, it is worth it.

Thanks for your input.
Roger Martin
Creator and Lead Developer of Gallery Server Pro
wiglebot
#3 Posted : Sunday, 7 June 2009 6:54:28 AM(UTC)
Rank: Member

Joined: 30/05/2009(UTC)
Posts: 3

Thanks for the detailed answer.
Not including install (I am not doing an install, but deploying from an install of the source) I will change the reading of the web.config to use the ConfigurationManager mostly for performance and efficiency. Then the reading and writing to the GSP.config will be an isolated performance hit. I might be wrong, but it seems the CSP.config can be change to GSP.xml and all the trust problems go away. I need to do that anyway for the policies of the server I am deploying to.

Thanks
Roger Martin
#4 Posted : Monday, 8 June 2009 2:07:41 AM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,300
Location: Fort Atkinson, WI

GSP already uses ConfigurationManager in all situations except installing and upgrading. Furthermore, this information is cached by GSP in static variables. I don't think you'll be able to improve the performance, but knock yourself out trying. :-)

I don't think changing the extension to .xml will make the Configuration API start working in medium trust. The config system in .NET works by combining all the config settings, starting with machine.config all the way down to local config files. Because medium trust apps cannot write to files outside the web directory, any attempt at writing fails, because it *potentially* updates machine.config.

My position that I have stated to MS is that this is poor architecture and needless hampers web sites, but as I said they are not correcting it.
Roger Martin
Creator and Lead Developer of Gallery Server Pro
Rss Feed  Atom Feed
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.