I'm trying to read the web.config for a web app from the code-behind DLL of an aspx page. However, all I'm getting back to the browser is
First I was trying this deploying the DLL to the web app's bin folder. To begin with, I got a FileIOPermission exception. I was able to get around this by adding a FileIOPermission attribute to the class in the aspx.cs. However, with that solved, all I get now is
403 Forbidden. I am testing this whilst logged in as the site administrator.
The code I'm using is:
SPWeb spWeb = SPContext.Current.Web; SPWebApplication webApp = spWeb.Site.WebApplication; Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApp.Name);
I'm using WSPBuilder and this creates the necessary Code Access Security policies for my DLL as far as I can see:
<NamedPermissionSets> ... <PermissionSet class="NamedPermissionSet" version="1" Description="WSPBuilder generated permissionSet" Name="mysolution.wsp-575f9c91-53d5-4a70-825b-b9a025c24427-1"> ... <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> ... </PermissionSet> ... </NamedPermissionSets>
These are in a custom trust file in 12/CONFIG, which is referenced by the web app's web.config.
I also tried deploying the DLL to the GAC instead of bin, but exactly the same error -
403 Forbidden. I wonder what I'm missing?