File upload doesnt work within New Posts

Jan 26, 2010 at 12:04 AM

My client tried to upload an image with her post and recieved an error:

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.

I opened a support issue with the host and was told that the highest level of trust they allow is Medium. Is there anything i can do to work around this? My client is expecting to upload images with her posts..

thanks

Coordinator
Jan 26, 2010 at 5:23 AM

According to this and this, FileIOPermission is permitted by default with medium trust -- as long as you're trying to write to files within your own application folder.

I would make sure Write permissions are setup correctly on the App_Data folder.  That's where images and files get saved to.

Coordinator
Jan 26, 2010 at 5:26 AM

Also, based on your other experience, it sounds a lot like Write permissions aren't setup correctly on the App_Data folder.

If write permissions aren't setup, changes you make like deleting comments, editing posts, etc. will take effect for the data in memory, but if the changes aren't written to disk, then the next time the app pool recycles or server is restarted, the data will get re-read from the App_Data folder and you'll be getting the old data.

Jan 29, 2010 at 2:24 AM
Edited Jan 29, 2010 at 2:27 AM

So since i have App_Data for the root of the site and within the blog application, they need to make sure they provided the correct read/write permissions to the one within the BLOG.

And within what folder are the images saves when adding an image to a post?

 It just sucks that i cant verify they applied the permissions correctly, other than trying after they reply that its done..

Other hosts i have full control and can set the permissions myself.

IF they apply the permissions as they should and it still doesnt work, what can i do to allow my client to upload images to her BLOG?

Coordinator
Jan 29, 2010 at 3:06 AM

BE saves files in many of the folders throughout App_Data.  This is why it's necessary to grant the ASPNET account (or Network Services account, etc), Write access to the entire App_Data folder.

For images in particular, when you click the Browse button, select the image, and then click the Upload button, at that moment is when the image will get saved to the App_Data\files folder.  It actually gets saved into a sub-folder from there based on the current year and month.  We're in January 2010 now, so the folder the image would get saved into would be App_Data\files\2010\1.  Next month, it'll be App_Data\files\2010\2.  BE will create these folders as needed.

BE also saves data in all the other files and sub-folders in App_Data.

You can try uploading an image to see if it gets saved in that folder.  You can also try saving the Settings in the control panel.  The settings.xml file in the App_Data folder should get updated.  These are just a couple of things you can test.

If your webhost cannot give Write permissions to the App_Data folder (which of course these is no reason why they shouldn't), you could have her upload images to remote image storage services (e.g. flickr) and then reference those remote images from her posts.  But this is not a "real" solution since storing images in App_Data is just one of the less important pieces of functionality needed for BE to be able to run.  BE also needs to be able to save Posts, Settings, and other pieces of data in App_Data too.

Jan 29, 2010 at 3:25 AM

i have emailed them earlier to reapply the permissions and just now to make sure they are applying it to the correct accounts for that folder.

hopefully that will do the trick.

thanks.

Jan 31, 2010 at 7:30 PM

They replied that the changes were made, but still not able to upload images, get the same error.

any other suggestions?

Coordinator
Jan 31, 2010 at 8:05 PM

What about when you Save Settings in the control panel.  Does the timestamp on the Settings.xml file in the App_Data folder get updated?

Do you have a DB available at that web hosting company?  You could use a DB, instead of the file system and App_Data.  However, even when you use a DB, images still get stored into App_Data.  So switching to a DB won't help with images.

But if I recall correctly, images are not the only problem you're having, right?  In this issue, you said changes you make in the administration area (like the Settings, I suppose) aren't sticking.  When you try and make changes in the admin area, like saving Settings, if the files in App_Data aren't getting updated (in the case of settings, it is the settings.xml file), then really the problem with images is only one of the many problems you have.

A requirement of BE is to have write permissions enabled on the App_Data folder.  I would check and see if any of the files within App_Data are getting updated.  Settings.xml, Categories.xml, etc.

Feb 7, 2010 at 8:58 PM

My issue was that the folder structure needed for the file upload location was not being created on the server although the permissions would allow me to create the folder outside the scope of BE installation (i.e manually).

There is an article that describes exactly what is going on with my version of BE here: http://forums.iis.net/t/1156286.aspx

Apparently there is a problem with Medium trust, and FileIOPermissions not working correctly in Windows Server 2008/IIS7 that to my knowledge is still unresolved. Microsoft has escalated it to the .NET product team... 

Feb 7, 2010 at 9:03 PM

Just to further clarify, I have manually created the expected file system structure and the upload does work as expected without any other changes!

Path created: {Application Root}\App_Data\files\2010\2