簡體   English   中英

安全異常WCF

[英]Security Exception WCF

我有一個可以運行的網站。 今天,我像往常一樣對Service進行了簡單的更改,將其重新編譯並上傳到生產環境中。 然后,我得到了一個奇怪的安全異常說:

Server Error in '/' Application.

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.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
   System.Security.CodeAccessPermission.Demand() +46
   System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Module m, StackCrawlMark& stackMark, Boolean skipVisibility) +248
   System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Module m, Boolean skipVisibility) +49
   System.Runtime.Serialization.CodeGenerator.BeginMethod(Type returnType, String methodName, Type[] argTypes, Boolean allowPrivateMemberAccess) +53
   System.Runtime.Serialization.CodeGenerator.BeginMethod(String methodName, Type delegateType, Boolean allowPrivateMemberAccess) +131
   System.Runtime.Serialization.CriticalHelper.GenerateClassReader(ClassDataContract classContract) +141

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

我尋找解決方案,但發現許多鏈接,但它們都不起作用。 我不知道這個錯誤的來源,無處……只是為了您的信息-更改只是在實體框架中添加了一個字段。

6個小時后,我放棄並在這里發布了問題。

有任何想法嗎?

這不是錯誤。 可能您嘗試在僅允許PartialTrust的主機上運行需要FullTrust的應用程序。

特別是對於WCF,某些綁定(如NetTCP)只是不支持部分信任級別,而需要完全信任。

因此,您需要知道應用程序需要哪種信任級別,然后使其在服務器上發生:)

我找到了我的案子的答案!

我在WCF中進行了2項更改以解決問題,所以我不知道到底是什么解決方法,但這可能是它們的組合:

  1. 首先,我注意到我添加了配置為對NULL值“引發異常”的新字段。 將其更改為“空”非常重要,這樣服務在這種情況下不會引發任何異常。 但錯誤消息不適合此錯誤,因為將排除“空錯誤”。

  2. 我所做的另一件事是-從存儲過程中獲取數據表,而不是作為“硬編碼” sql語句。

在我看來,后者確實可以解決問題,因為在我看來,這與安全性問題更為相關,但這只是一種假設,因為第一步是非常重要的一步。

就這樣。 它現在可以正常工作,謝謝您的答復,希望我的答復能在某個時候對某人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM