2010-05-20 103 views
1
創建新的FileInfo當

我得到文件上載到Rackspace的雲文件時,出現以下異常:拋出:SecurityException在Rackspace公司

安全例外
說明:應用程序試圖執行不允許的操作不 由安全政策。要向 授予此應用程序所需的 權限,請聯繫您的系統管理員或在 配置文件中更改 應用程序的信任級別。

異常詳細信息信息:System.Security.SecurityException: 請求類型的 「System.Security.Permissions.FileIOPermission, mscorlib程序許可,版本= 2.0.0.0, 文化=中立, 公鑰= 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; 
    } 
+0

好吧,有時只是發佈問題有助於解決問題。該文件已存在於服務器上.... 我想這裏的問題是'爲什麼我不能使用FileInfo'或'我真的需要使用它 - 我想我可以解決它' – earthling 2010-05-20 17:28:00

回答

0

各地使用的FileInfo工作。將代碼更改爲以下內容。這是最好的解決方案嗎?

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

它看起來像您的應用程序運行在中等信任或更低。看看這個博客帖子大約信任級別以及如何可能能夠改變他們...這取決於Rackspace公司是如何配置的東西:

ASP.NET trust levels demystified

+0

謝謝,試過了並得到一個錯誤,我無法更改由於繼承設置而產生的信任級別。 – earthling 2010-05-20 17:29:10

+0

@senloe - 這就是我想要發生的事情。在託管環境中,通常不能直接訪問文件系統(因爲它通常是共享環境)。 – 2010-05-20 17:32:20

相關問題