tags:

views:

23

answers:

2

I am using the following code to open up an XML file so that I can utilize it for content management:

    //Initialize and load xmlDoc
    XmlDocument XMLDoc = new XmlDocument();
    XMLDoc.Load("E:\\foldername\\Content.xml");
    FileStream fileStrm = new FileStream("E:\\EightFoldDev\\Content.xml", FileMode.Open);
    XMLDoc.Load(fileStrm);
    fileStrm.Close();

However I am getting an error:

"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.

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

I have been looking around online but haven't been able to find a solution yet. I tried adding the following to web.config but had no luck.

    <securityPolicy>
  <trustLevel name="Full" policyFile="internal"/>
</securityPolicy>

It works on my local machine fine but when I push it up to the server (hosting provided by WinHost), I get the error. So I'm sure there's something I am missing in permissions.

Any help is appreciated!

A: 

Since it appears your application is running inside ASP.NET running in partial trust (probably medium) you cannot specify a physical path outisde your application root folder. So you will need to adjust it to something like: XmlDocument XMLDoc = new XmlDocument(); XMLDoc.Load(Server.MapPath("~/App_Data/Content.xml"));

CarlosAg
I actually tried a relative path before but it didn't work. I just tried moving Content.xml to the app_data folder and changing the code to reference it but no luck. Same error
fireSoulDinner
+1  A: 

For some reason in WinHost I had to log in to IIS (connect remotely using IIS Manager), set the permissions down to medium and then back up to Full....no idea why it is necessary, but it seemed to fix my problem.

Also, I was able to use a direct path no problem ("E:\foldername\Content.xml"). Relative paths seemed to try and start from C: regardless of what I did. This ONLY seemed to happen when calling the XMLDocument Load method.

fireSoulDinner