2012-02-27 19 views
2

我的MVC c#項目存在一些問題。ASP.NET 4.0中的代碼訪問安全和動態數據錯誤

首先我收到此錯誤:級別2的透明度導致AllowPartiallyTrustedCallers程序集中的所有方法默認情況下變爲安全透明,這可能是此異常的原因。完成:

Attempt by security transparent method 'System.Runtime.Diagnostics.DiagnosticTrace..ctor(System.String, System.Guid)' to access security critical method 'System.Runtime.Diagnostics.EtwDiagnosticTrace..ctor(System.String, System.Guid)' failed.

Assembly 'System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception."

因此,我在互聯網上搜索和找到解決它的兩種可能性。第一個作品,包括assemblyinfo.cs這個片段:

[assembly: System.Security.AllowPartiallyTrustedCallers] 

,但沒有改變..

谷歌搜索我找到了第二個信息說,如果我在web.config把它可能工作。

<trust legacyCasModel="true" level="Full" /> 

但是,當我把這些信息在web.config我接受和錯誤,如

Dynamic operations can only be performed in homogenous AppDomain

,我不知道還有什麼做我必須做的......

我相信使用microsoft.practices.unity與ASP.NET 4.0和mvc 4,是問題的主要原因。但基於我的應用程序的工作方式,對我來說使用統一是必要的。

brgds!塞巴斯蒂安。

+0

@DarinDimitrov你知道如何解決這個問題問題?,非常感謝你提前.. – 2012-02-27 06:30:08

+0

@ marc-s謝謝你的ediition ...你有任何想法,爲什麼這可能嗎? brgds – 2012-02-27 07:33:36

回答

5

在.NET 4.0框架,新的CAS模式可以防止任何安全透明代碼調用到安全關鍵代碼

從你已經上述異常,似乎都認爲你調用的方法屬於一個外部庫(命名空間System.Runtime.Diagnostics),而不是你的代碼甚至你的程序集。

一個外部庫的方法試圖訪問該庫的另一種方法時拋出的事實,表明在該庫或某種二進制或配置不匹配問題的錯誤的可能性(根據此線程http://social.msdn.microsoft.com/Forums/en-US/netfxsetup/thread/a8ceb77b-f625-4259-94de-4ae5157ba98c

「legacyCasModel」切換到非同類(或簡稱CAS 1)應用程序域。這意味着動態和舊的CAS設置不兼容。此外,MVC 3在其自己的代碼中使用了動態(請參閱ASP.NET MVC 3中的ViewBag動態),因此最有可能的是,MVC 4也是如此。

,而不是切換到傳統的CAS 1,你可以嘗試添加具有System.Runtime.Diagnostics命名大會FullTrustAssembliesSection web.config文件的

http://msdn.microsoft.com/en-us/library/system.web.configuration.fulltrustassembliessection.aspx

+0

您好我正在研究提議的解決方案。我有一個疑問,如果我使用fullTrustAssemblies它的必要性使用公鑰或我可以使用publickeytoken ..我找不到方法來查看system.servicemodel公共密鑰... brgds! – 2012-02-28 03:49:57

+1

@sebastian_h:根據文檔,你需要公鑰。要查看公共或公共令牌,可以嘗試(從VS命令提示符)sn -T System.ServiceModel.Internals.dll?有關更多信息,請參閱Sn.exe(強名稱工具)文檔http:// msdn。microsoft.com/en-us/library/k5b5tt23.aspx。另外,我會嘗試在不同的機器上執行相同的方案,以確保.NET Framework和ASP.NET在您的開發箱上正確安裝和配置 – user1234883 2012-02-28 04:30:39

+1

非常感謝,最終我找到了使用vs命令的公鑰提示,但一切都保持不變。我相信我必須刪除一切並重新安裝網絡框架和asp.net。儘管昨天我恢復了這兩項安裝,但它似乎與此有關。大概當我用.net 4.5來試用VS2011時,一些東西被改變了......非常感謝你的支持! brgds – 2012-02-28 04:50:54