开发者

SecurityException when creating new FileInfo on Rackspace

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
            {
               开发者_Go百科 Name = f.Name;
            }

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

        return storageItemName;
    }


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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜