views:

50

answers:

2

I'm getting the following exception when uploading a file to Rackspace Cloud Files:

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

It seems to only happen with this file.

It is happening in a method where I check for a unique file name and I can't seem to figure out why.

    private string GetUniqueStorageItemName(string storageItemName)
    {
        int count = 0;
        string Name = "";


        if (cloudConnection.GetContainerItemList(Container).Contains(storageItemName))
        {
            System.IO.FileInfo f = new System.IO.FileInfo(storageItemName); // error on this line
            if (!string.IsNullOrEmpty(f.Extension))
            {
                Name = f.Name.Substring(0, f.Name.LastIndexOf('.'));
            }
            else
            {
                Name = f.Name;
            }

            while (cloudConnection.GetContainerItemList(Container).Contains(storageItemName))
            {
                count++;
                storageItemName = Name + count.ToString() + f.Extension;
            }
        }

        return storageItemName;
    }
+2  A: 

It looks like your application is running at Medium Trust or lower. Take a look at this blog post about Trust Levels and how you might be able to change them...it depends on how Rackspace configures things:

ASP.NET trust levels demystified

Justin Niessner
thanks, tried that and got an error that I cannot change the trust level due to inherited settings.
senloe
@senloe - That's what I figured would happen. When in hosted environments, it's typical that you can't access the File System directly (since it's often a shared environment).
Justin Niessner
A: 

Working around using FileInfo. Changed the code to the following. Is this the best solution?

            if(storageItemName.Contains('.'))
            {
                Name = storageItemName.Substring(0, storageItemName.LastIndexOf('.'));
                Ext = storageItemName.Substring(storageItemName.LastIndexOf('.'), storageItemName.Length - storageItemName.LastIndexOf('.'));
            }
            else
                Name = storageItemName;
senloe