update web.config permission

liming

Perch
Anybody used the .NET configuration API to update the web.config here on jodo?

on one of my sub domain here, everything is fine, but on another, the exact same code caused a security permission, i just can't figure out why the differences. Here is my code and exception


Configuration config;
config=System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

ConnectionStringsSection connect_sect=config.ConnectionStrings;
connect_sect.ConnectionStrings["LocalSqlServer"].ConnectionString="";

config.Save();


-------------------------------------
An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams) at System.Configuration.Internal.InternalConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(Type typeConfigHost, Object[] hostInitConfigurationParams) at System.Web.Configuration.WebConfigurationHost.OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, String site, String locationSubPath, String server, String userName, String password, IntPtr tokenHandle) at System.Web.Configuration.WebConfigurationManager.OpenWebConfigurationImpl(WebLevel webLevel, ConfigurationFileMap fileMap, String path, String site, String locationSubPath, String server, String userName, String password, IntPtr userToken) at System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(String path)
 
never mind. did some search

Using the Configuration Classes
---
To open a section in a Web configuration file, the application needs Read permission for the physical Web.config file, and for all of its parent files in the hierarchy. Managed code applications need to have permission to read system sections. Full Trust and High Trust applications have these permissions by default. In other words, by default, medium and lower trust applications will not be able to read configuration sections.
--

it's still weird that one of my sub domain is actually able to do it though... seems like different servers here have differnet kinds of permission, that's what's really werid.
 
Liming, I am copying and pasting the config into place :) And I am the only one that edits, Win2 and Win13 have different permissions than all the others. Win14+ are the same
 
Thanks again Stephen. I was trying to debug if I did something wrong and obviously, after the research, I realized OpenWebConfiguration() method is a design time method, which is not suppose to be used at runtime in a medium trust as indicated by that msdn2 documentation.

so yeah, the web servers that have the file permission denied message were suppose to be like that. So now I've changed the way i modify the web.config by pointing the things i need to change in a web.config to an external xml file, that solved my issues.

Thanks again.
 
Hi,
May I know how did you do that? I am trying to encrypt the connection strings in my web.config and I get the same error when I am trying to do that.

Cheers,
Sean
 
Back
Top