reading web.config section

A

alf

Hi folks,
I'm trying to read a web.config section using

RoleManagerSection settings =
(RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager");

and I get the following error on the page:

Security Exception
Description: The application attempted to perform an operation not allowed
by the security policy. To grant this application the required permission
please contact your system administrator or change the application's trust
level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the
permission of type 'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

There is any security restriction on the server?? there is other way to
acces config information ??

Thanks
 
A

alf

Hi Timmey,
I can't set y application because I'm running in a hosting enviroment where
the security level is Medium.
I can read the sections: "appSetting" and "connectionStrings" perfectly but
not the "system.web"... why ???

any idea ??
thanks
 
A

alf

Well, I tryed a lot to get understan with this guys from the support staff,
but nothing, they just repeat and repeat that the server has Medium Level.

Doing some test I found that:
GetSection("appSettings"); // OK to read
GetSection("connectionString"); // OK to read
GetSection("system.web"); // Unable to read. Security Exception

I just wanna know WHY system.web is impossible to access !!!

Anyway, now I can read the entire web.config file using XmlDocument. So, my
problem is solved but I would like to investigate about it.
 
J

Juan T. Llibre

re:
!> I just wanna know WHY system.web is impossible to access !!!
!> my problem is solved but I would like to investigate about it

Your ISP is assigning restrictive access permissions to some sections of web.config.

Try adding
---------------------------------------------
<location allowOverride="true">
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal" />
<trustLevel name="High" policyFile="web_hightrust.config" />
<trustLevel name="Medium" policyFile="web_mediumtrust.config" />
<trustLevel name="Low" policyFile="web_lowtrust.config" />
<trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
</securityPolicy>
<trust
level="Full"
originUrl=""
processRequestInApplicationTrust="true"
/>
</system.web>
</location>
-------------

....to the root web.config, and see if you can assign trust settings to your app, per:
http://msdn2.microsoft.com/en-us/library/tkscy493(VS.80).aspx

If you can't, you'll have to talk to your ISP about allowing you to override the trust settings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top