程序集不允许部分信任的调用者
如何更改我的库以允许部分信任的调用者?
我收到以下错误:
“/”应用程序中的服务器错误。
安全异常
描述:已尝试应用程序 执行不允许的操作 安全政策。为了授予此 申请所需的权限 请联系您的系统 管理员或更改 应用程序的信任级别 配置文件。
异常详细信息: 系统.安全.安全异常: 该大会不允许部分 值得信赖的来电者。
来源错误:[无相关来源 行]
源文件:App_Web_kzj7vfkn.2.cs
行:0
编辑
经过更多查看问题后,似乎是 System.Web.UI.ClientScriptManager 导致了问题
How do I change my library to allow partially trusted callers?
I get the following error:
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:
That assembly does not allow partially
trusted callers.Source Error: [No relevant source
lines]Source File: App_Web_kzj7vfkn.2.cs
Line: 0
Edit
After some more looking at the problem it seems like it's System.Web.UI.ClientScriptManager that causes the problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
假设您可以访问图书馆的资源。
称呼。
此处给出了非常好的详细解释 另请阅读底部的链接以获得更好的理解。
有可能不是您的程序集有问题,而是您正在调用另一个不允许部分受信任的调用者的程序集。在运行时,您可以使用 fuslogvw 来查找装配给你带来了问题。如果这是问题所在,并且您拥有此程序集的源代码,则还需要应用 [程序集:AllowPartiallyTrustedCallers] 属性到该程序集,如果您没有源,我知道的唯一选择是替换麻烦的库。
Assuming you have access to the sources of your library.
call.
A pretty good and detailed explanation is given here Also read the links at the bottom to get a better understanding.
There is a possibility that not your assembly is the problem but you are calling another assembly that does not allow partially trusted callers. At runtime you can use fuslogvw to find which assembly is giving you the problems. If this is the problem and you have the sources of this assembly you need to also apply the [assembly:AllowPartiallyTrustedCallers] attribute to that assembly, if you don't have the sources the only option I know of is to replace the troublesome library.
就我而言 -
这解决了类似的问题:
我必须转到我的 dll 属性,
然后按取消阻止按钮:
In my case -
This solved a similar problem:
I had to go to my dll properties,
And press the Unblock button:
我知道回答已经很晚了,但我想再添加一个答案,以帮助未来的访客。
我的场景
当我遇到此问题时,我正在我的
asp.net
应用程序中实现 CCavenue 支付网关,因为 CCavenue 加密MCPG.CCA。 Util
请在
web.config
中添加以下行I know its quite late to answer, but I would like to add one more answer just to help future visitors.
My Scenario
I was implementing CCavenue Payment gateway in my
asp.net
application when I had this issue becuase CCavenue encryptionMCPG.CCA.Util
Please add the following lines in
web.config
我知道这是一个非常老的问题,但我刚刚遇到了这个问题,并且能够使用与接受的答案不同的方法来修复它,因为这是搜索错误消息时谷歌上的第一个结果,我认为这会很有用如果我分享我的解决方案给其他人。
当我尝试与硬件集成时,出现了我遇到的问题。硬件有自己的安装程序,可以将 DLL 注册到 GAC 中。它安装的 DLL 有 2 个依赖项 DLL,但由于某种原因,当安装程序运行时,它没有注册依赖项 DLL。
基本上情况是,Entry DLL 已在 GAC 中注册,而其两个依赖项 DLL 未在 GAC 中注册,但确实存在于可执行文件旁边。
当我运行我的程序并尝试使用该硬件时,程序正在寻找可执行文件旁边的入口 DLL,但它找不到。然后程序将进入 GAC,在那里找到入口 DLL。一旦进入硬件的 DLL,它最终会尝试使用不在 GAC 中但位于可执行文件旁边的依赖项 DLL。从 GAC 调用可执行文件旁边的 DLL 会引发部分受信任的调用者错误。
我通过将入口 DLL 的副本放在可执行文件旁边解决了这个问题。
我很好奇什么情况会起作用以及什么会导致安全错误,我发现这些情况按预期工作:
唯一始终失败的情况是任何层位于 GAC 内部且任何依赖项 DLL 位于 GAC 外部时。
失败场景 #1:
Exe 旁边的 DLL #2 和 DLL #3
失败场景 #2:
Exe 旁边的 DLL #3 中输入 DLL 和 DLL #2
失败场景 #3:
exe 旁边的 DLL #2 中输入 DLL 和 DLL #3
我没有测试它,但我认为这是一个安全的假设,如果条目 DLL 和 DLL #3 位于可执行文件旁边,并且 DLL #2 位于 GAC 中,那么它会因为 DLL #3 被定位为而出错问题。
I know this is a very old question but I just ran into this issue and was able to fix it using a different method than the accepted answer and since this is the first result on google when searching for the error message I think it will be useful to others if I share my solution.
The issue I was running into came about when I attempted to integrate with a piece of hardware. The hardware had its own installer which would register a DLL into the GAC. The DLL it installed had 2 dependency DLLs but for some reason when the installer was run it was not registering the dependency DLLs.
Basically the scenario was that the Entry DLL was registered in the GAC and its two dependency DLLs were not registered in the GAC but did exist next to the executable.
When I ran my program and attempted to use the piece of hardware, the program was looking for the entry DLL next to the executable, which it could not find. The program would then go to the GAC, where it would find the entry DLL. Once inside the DLL for the hardware it would eventually try to use the dependency DLLs which were not in the GAC but were next to the executable. Calling out of the GAC to the DLL that was next to the executable was throwing the partially trusted caller error.
I resolved this by placing a copy of the entry DLL next to the executable.
I was curious as to what scenarios would work and what would cause the security error and I've found these are the scenarios that worked as expected:
The only scenario that consistently failed was when any layer was inside the GAC and any of the dependency DLLs were outside the GAC.
Failed Scenario #1:
DLL #2 and DLL #3 next to the Exe
Failed Scenario #2:
DLL #3 next to the Exe
Failed Scenario #3:
DLL #2 next to the exe
I did not test it but I think its a safe assumption to say that if the entry DLL and DLL #3 had been next to the executable and DLL #2 had been in the GAC then it would have faulted with DLL #3 being sited as the problem.
我也遇到了类似的问题,我尝试了上述所有答案,但没有一个对我有用。显然我的情况有所不同,在我的情况下,框架是 3.5。我将其更改为 4 或以上,它对我有用。
I also got the similar problem, I tried all the above answers but none worked for me. Apparently my case was different, In my case the framework was 3.5. I changed it to 4 or above and it worked for me.
这是另一个可能的解决方案,具体取决于您正在使用的库和您的设置: 确保您从“本地”驱动器运行程序。
当我在主机和来宾操作系统之间共享的文件夹中的虚拟机中运行程序时,我遇到了此错误消息,并且库 dll 位于 exe 旁边。将文件夹复制到来宾操作系统本地驱动器修复了该问题。
这会导致信任问题,这是有道理的,但如果能提供更有用的错误消息就更好了。
Here's yet another possible solution, depending on the library you're using and your setup: Make sure you're running your program from a "local" drive.
I ran into this error message when running my program in a VM in a folder shared between host and guest OS, with the library dll present beside the exe. Copying the folder to a drive local to the guest OS fixed the issue.
It makes sense that this would cause a trust issue, but a more helpful error message would be nice.