Hi Roger,
==================================================
'¡*. despite being able to access custom
sections, one cannot access pre-defined sections such as Membership. Can
you
confirm?'
==================================================
Sorry that my statement is not very clear. In medium trust, by default,
it's only allowed to access the section defined in the Web.config file that
is in the application directory. It's not allowed to read the configuration
settings in the machine.config file. Since the membership section is
defined in the machine.config it violates the security policy when calling
WebConfigurationManager.GetSection("system.web/membership").
==================================================
'¡*.the only answer is to use the XmlReader class (Linq is not
available in my .NET 2.0 app). If you have any sample code that shows how
to
access the Membership section this way, I would really appreciate it'
==================================================
To use XmlReader to read the Web.config file you can try this:
string xml = "";
using (FileStream fs = new
FileStream(Server.MapPath("Web.config"), FileMode.Open, FileAccess.Read,
FileShare.Read)) {
using (StreamReader sr = new StreamReader(fs)) {
XmlReader r = XmlReader.Create(sr);
while (r.Read()) {
if (r.Name == "membership")
{
xml= r.ReadInnerXml();
break;
}
}
}
}
Response.Write(HttpUtility.HtmlEncode( xml));
Please have a try and feel free to let me know if you need further
assistance.
Regards,
Allen Chen
Microsoft Online Support
--------------------
| Thread-Topic: WebConfigurationManager.GetSection in Medium Trust
| thread-index: AckC1QDYNcXdV3e4RtijJ2mqnWrX/A==
| X-WBNR-Posting-Host: 207.46.19.168
| From: =?Utf-8?B?Um9nZXIgTWFydGlu?= <Roger
Ma****@community.nospam>
| References: <0E**********************************@microsoft.co m>
<AG**************@TK2MSFTNGHUB02.phx.gbl>
| Subject: RE: WebConfigurationManager.GetSection in Medium Trust
| Date: Wed, 20 Aug 2008 07:57:02 -0700
| Lines: 40
| Message-ID: <18**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74316
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Perhaps you are not aware of this, but it *is* possible to call
| WebConfigurationManager.GetSection() method in medium trust.
|
| I already do this for a new section named galleryServerPro I added to
| web.config. I defined the section like this:
|
| <configSections>
| <sectionGroup name="system.web">
| <section name="galleryServerPro"
| type="GalleryServerPro.Configuration.GalleryServer ProConfigSettings,
| GalleryServerPro.Configuration" allowDefinition="MachineToApplication"
| restartOnExternalChanges="true" requirePermission="false" />
| </sectionGroup>
| </configSections>
|
| Then I can access it like this:
|
| GalleryServerProConfigSettings _alleryServerProConfigSection =
|
(GalleryServerProConfigSettings)System.Web.Configu ration.WebConfigurationMan
ager.GetSection("system.web/galleryServerPro");
|
| This works in Medium Trust. All I want to do is access the Membership
| section as well.
|
| I suspect the real answer is that, despite being able to access custom
| sections, one cannot access pre-defined sections such as Membership. Can
you
| confirm?
|
| Being able to access the AppSettings section does not help me access the
| Membership section, so that is not a viable solution, unless of course if
I
| duplicate my settings in both the Membership and AppSettings section, but
| that violates best practices.
|
| It appears the only answer is to use the XmlReader class (Linq is not
| available in my .NET 2.0 app). If you have any sample code that shows how
to
| access the Membership section this way, I would really appreciate it,
| otherwise I can probably muddle through it on my own.
|
| Thanks,
| Roger
|
|