简体   繁体   English

安全异常WCF

[英]Security Exception WCF

i have a website that up and running. 我有一个可以运行的网站。 today, as usual, i did a simple change in the Service, re-compiled it and upload it to production. 今天,我像往常一样对Service进行了简单的更改,将其重新编译并上传到生产环境中。 then, i got a strange Security Exception saying: 然后,我得到了一个奇怪的安全异常说:

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

I looked for a solution, and found many links but neither of them worked. 我寻找解决方案,但发现许多链接,但它们都不起作用。 i have no clue where this bug came from, out of nowhere... just for your information - the change was just adding a field to entity framework. 我不知道这个错误的来源,无处……只是为了您的信息-更改只是在实体框架中添加了一个字段。

after 6 hours i gave up and posted here the problem. 6个小时后,我放弃并在这里发布了问题。

any ideas? 有任何想法吗?

It is not a bug. 这不是错误。 Probably you try to run the application that requires FullTrust on the hosting that only allows PartialTrust. 可能您尝试在仅允许PartialTrust的主机上运行需要FullTrust的应用程序。

Especially with WCF, some of the bindings (like NetTCP) just do not support partial trust level and require a full trust one. 特别是对于WCF,某些绑定(如NetTCP)只是不支持部分信任级别,而需要完全信任。

So you need to know which trust level is required by your application and then make it happen on your servers :) 因此,您需要知道应用程序需要哪种信任级别,然后使其在服务器上发生:)

i found the answer for my case ! 我找到了我的案子的答案!

i made 2 changes in my WCF that did the trick, so i dont know exactly what solve it, but it may be the mix of them: 我在WCF中进行了2项更改以解决问题,所以我不知道到底是什么解决方法,但这可能是它们的组合:

  1. first, i've noticed that the new field that i added what configured to "throw exception" on NULL values. 首先,我注意到我添加了配置为对NULL值“引发异常”的新字段。 it very important to change it to "empty" so the service wont throw any exception in that case. 将其更改为“空”非常重要,这样服务在这种情况下不会引发任何异常。 but the error message doesn't fit to this error, as "null error" would be excepted. 但错误消息不适合此错误,因为将排除“空错误”。

  2. the other thing that i've done is - getting the DataTable from a Stored Procedure and not as "hard coded" sql statement. 我所做的另一件事是-从存储过程中获取数据表,而不是作为“硬编码” sql语句。

it seems to me that the latter did the trick, as it seem to me more related to security issue, but it is just an assumption, as the first step was very important step to do. 在我看来,后者确实可以解决问题,因为在我看来,这与安全性问题更为相关,但这只是一种假设,因为第一步是非常重要的一步。

that's all. 就这样。 it works now, thank you for your reply, hope my answer will help someone sometime. 它现在可以正常工作,谢谢您的答复,希望我的答复能在某个时候对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM