代码之家  ›  专栏  ›  技术社区  ›  earthling

在Rackspace上创建新文件信息时的SecurityException

  •  1
  • earthling  · 技术社区  · 16 年前

    将文件上载到rackspace云文件时出现以下异常:

    安全例外
    描述 :应用程序试图执行的操作不是 安全策略允许。到 授予此应用程序所需的 权限请联系您的系统 管理员或更改 应用程序的信任级别 配置文件。

    异常详细信息 :System.Security.SecurityException: 请求类型的权限 'system.security.permissions.fileiopermission,' mscorlib,版本=2.0.0.0, 文化=中性, publickeytoken=b77a5c561934e089' 失败

    这似乎只发生在这个文件中。

    这种情况发生在一个方法中,我检查一个唯一的文件名,但我似乎无法找出原因。

        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 回复  |  直到 16 年前
        1
  •  2
  •   Justin Niessner    16 年前

    您的应用程序似乎以中级信任或更低级别运行。看看这篇关于信任水平和你如何 可以 能够改变它们…这取决于Rackspace如何配置:

    ASP.NET trust levels demystified

        2
  •  0
  •   earthling    16 年前

    使用fileinfo。将代码更改为以下。这是最好的解决方案吗?

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