|
|
|
start date: Tue, 14 Aug 2007 19:22:01 -0700,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Roger Martin Roger am
|
|
2
(Walter Wang [MSFT])
|
|
3
Roger Martin Roger am
|
|
4
(Walter Wang [MSFT])
|
|
5
(Walter Wang [MSFT])
|
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.OpenWebConfiguration("~/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
Date:Tue, 14 Aug 2007 19:22:01 -0700
Author:
|
RE: Save config data in Medium Trust
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 (wawang@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.
Date:Wed, 15 Aug 2007 08:19:21 GMT
Author:
|
RE: Save config data in Medium Trust
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
Date:Thu, 16 Aug 2007 17:45:39 -0700
Author:
|
RE: Save config data in Medium Trust
Hi Roger,
I somehow overlooked the requirement is to "save" instead of "read-only",
sorry.
I just re-checked the document and confirmed that
WebConfigurationManager.OpenWebConfiguration requires Full Trust.
I'll do some further researching and consulting to see if there's other
solution to this issue other than creating a separate assembly and install
into GAC to give it Full Trust.
Regards,
Walter Wang (wawang@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.
Date:Fri, 17 Aug 2007 08:34:45 GMT
Author:
|
RE: Save config data in Medium Trust
Hi Roger,
Sorry for late reply. I've been consulting your question within our
internal discussion list.
Unfortunately there's no other good way to edit web site's web.config under
medium trust. Currently the OpenWebConfiguration will always require full
trust to run; and we have to use it to get a reference to the configuration
items. Sorry for the inconvenience caused.
If you don't want to create a separate assembly and give it full trust or
create a custom policy, then you might have to fallback to plain xml
document processing to edit the web configuration.
#How To: Use Medium Trust in ASP.NET 2.0
http://msdn2.microsoft.com/en-us/library/ms998341.aspx
Regards,
Walter Wang (wawang@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.
Date:Wed, 22 Aug 2007 03:45:21 GMT
Author:
|
|
|