473,467 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Save config data in Medium Trust

I have configuration data for a web application stored in a file
galleryserverpro.config located in a config folder off the root application.
Web.config references this file like this:
<galleryServerPro configSource="config\galleryserverpro.config"/>

I built a custom configuration settings class (inherited from
ConfigurationSection) to access this data and it works great in Full Trust.
However, in Medium Trust I get a SecurityException on the following line:

System.Configuration.Configuration config =
System.Web.Configuration.WebConfigurationManager.O penWebConfiguration("~/config/galleryserverpro.config");

It is failing because OpenWebConfiguration is trying to access
machine.config, which is not accessible under Medium Trust.

This is a web application meant for wide deployment and I have no control
over the hosting providers, so it must work in Medium Trust without any
policy alterations.

What are my options? The only idea I found was to abandon using the
configuration classes of .NET 2.0 and instead use XML classes and treat it as
an XML file. I don't want to do this because I will lose all the wonderful
features - like data type checking - of the .NET 2.0 configuration model!

I don't want to update machine.config - I only want to update this
particular file. I have 100+ configuration settings in it and I am faced with
many hours of work to port this to an XML read/write model. Hopefully I am
missing something simple.

Regards,
Roger Martin
Gallery Server Pro / www.galleryserverpro.com
Aug 15 '07 #1
6 1693
Hi Roger,

In this case, since you're only trying to read your custom section, we can
use WebConfigurationManager.GetSection() to get the individual section
instead of the OpenWebConfiguration().

Here's a sample:

in web.config:

<configSections>
<section name="mySection"
type="System.Configuration.NameValueSectionHandler "
requirePermission="false" />
</configSections>
<mySection configSource="mySection.config" />

in mySection.config:

<mySection>
<add key="key1" value="value1" />
</mySection>

In code:

NameValueCollection cols = (NameValueCollection)
WebConfigurationManager.GetSection("mySection");
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 15 '07 #2
I am sorry, Walter, but the web app *is* writing to this config file. I built
a series of admin web pages that let users change config settings. Sorry if I
wasn't clear on this.

To rephrase the question: How can a web app in Medium Trust save changes to
one of its own config files that are being managed using the .NET 2.0
Configuration API? The config file is within the web app directory.

-Roger
Aug 17 '07 #3
Any word on this, Walter? This is the last major issue preventing my app from
working in medium trust.

Roger
Aug 23 '07 #4
Hi Roger,

Since the web site's web.config is actually inheriting some settings from
machine.config (or its parent folder's web.config, if there's any), the
WebConfigurationManager API will have to be able to access them to provide
full object model of the settings. Therefore I'm afraid there's no other
way to workaround this.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 27 '07 #5
Thanks for getting to the bottom of this, Walter. The inability to save
settings using the Configuration API in medium trust certainly takes all the
fun out of the API. I'll cross my fingers that .NET 3.5 addresses this issue.

Cheers,
Roger Martin
Aug 27 '07 #6
Hi Roger,

Thanks for your quick reply.

I agree this is a limitation of the Configuration API. Your feedback is
recorded and will be correctly forwarded to product team.

Please let me know if there's anything else I can help.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jorge Ochoa | last post by:
Hello every one: I have a problem: We have applications in a share server but they have changed the machine.config <trust level= "Full" to <trust level="Medium", this does not let me use...
0
by: Fabrice | last post by:
Hello, One question about security. I try to secure my web application on IIS6 and asp.net 1.1 I have differents questions about the element "trust level" in the config.web to manage...
0
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
0
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
7
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
5
by: alf | last post by:
Hi folks, I'm trying to read a web.config section using RoleManagerSection settings = (RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager"); and I...
1
by: gomzi | last post by:
hi, I would like to know as to which class I could use if I want to resize an image for a medium trust environment? I am currently using the getthumbnailimage property of the system.drawing.image...
1
by: Jordan M. | last post by:
Hi, Hopefully someone can help or at least point me in the right direction... I have developed a site that uses the CyberSource system to process credit cards. All works great locally on my...
0
by: ilkka | last post by:
Hi ! SimpleWorkerRequest class can be used to host asp.net pages outside of IIS. However when a web application is configured to run as medium trust (or lower), you will get an exception...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.