2009-12-22 68 views
0

的許可權我試圖將我的MOSS 2007 Web部件遷移到SharePoint 2010環境。
我的環境是Windows Server 2008 64Bit,Visual Studio 2008SharePoint 2010SecurityException未被用戶代碼處理。請求獲得類型爲'System.Security.Permissions.FileIOPermission

在其上添加Web部件現場後面的SharePoint 2010網站,它正在訪問的log4net的配置文件,這樣它產生一個錯誤說「拋出:SecurityException是由用戶代碼未處理」。

運行此行的代碼,同時它也越來越:

FileInfo fi = new FileInfo(log4netConfigFilePath); 
從異常類型

確切錯誤:

"Request for the permission of type 'System.Security.Permissions.FileIOPermission 
    , mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 
    failed." 

這是堆棧跟蹤:

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
    at System.Security.CodeAccessPermission.Demand() 
    at System.IO.FileInfo..ctor(String fileName) 
    at ProjectWorld.Logging.LogManager.Configure() 
    at ProjectWorld.Logging.LogManager.EnsureConfiguration() 
    at ProjectWorld.Logging.LogManager.GetLogger(WebPart webPart) 
    at ProjectWorld.WebParts.PRSWebParts.QBWebPart..ctor() 
    at T_c39ca68b_5b0a_4d36_b052_e470116a6771.CreateInstance() 
    at System.Web.HttpRuntime.FastCreatePublicInstance(Type type) 
    at System.Web.UI.WebControls.WebParts.WebPartManager.ImportWebPart(XmlReader reader, String& errorMessage) 

我試圖運行此代碼在Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges下,但它也產生了這個錯誤。

請幫我解決這個錯誤。

回答

-1

設置您的應用程序的web.config以完全信任的方式運行。 ()

最好是更改代碼並分配特權(請參閱代碼訪問安全性文檔),並將自定義信任文件與應用程序一起部署。

+0

喜應用程序了在完全信任水平已經運行 – 2009-12-24 07:03:09

0

我們有完全相同的問題,並通過將log4net配置文件信息初始化到OnInit方法內的構造函數之外來解決它。

這也適用於私有全局變量(具有非常類似的除外),例如:

private readonly SPList _projectList = SPContext.Current.Web.GetList(SPContext.Current.Web.ServerRelativeUrl + "/Lists/Inquiries"); 
相關問題